A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help: reading data from table



 
 
Thread Tools Display Modes
  #1  
Old September 22nd, 2004, 01:47 AM
ad
external usenet poster
 
Posts: n/a
Default Help: reading data from table

Hi
This must be another easy one for you guys:

I am trying to read all email addresses in a table into a string variable using "getrows".
I have searched the Internet for a few days and couldn't get it work for me. the following
is the code I come up with. It doesn't work. It stops at OpenRecordset saying type
missmatch.

Please help......

ad

=============================
Sub test()

Dim db As Database
Dim Lrs As Recordset
Dim LSQL As String
Dim email As Variant
Dim c As Integer
Dim strEmail As String

'Open connection to current Access database
Set db = CurrentDb()

'Create SQL statement to retrieve value from GST table
LSQL = "SELECT Contacts.[E-Mail Address] FROM MailingList INNER JOIN Contacts ON MailingList.ContactID = Contacts.[Contact ID];"

Set Lrs = db.OpenRecordset(LSQL)
email = Lrs.GetRows

For c = 1 To 2
strEmail = strEmail & email(c) & "; "
Next c

' Display the results.
MsgBox strEmail

Lrs.Close
Set Lrs = Nothing


End Sub


  #2  
Old September 22nd, 2004, 02:35 AM
Van T. Dinh
external usenet poster
 
Posts: n/a
Default

You don't need the GetRows Method. All you need to do is
to traverse the Recordset and use concatenation to append
to the strEmail as you traverse the Recordset using a loop.

Check Access Help on the MoveNext Method of the Recordset.

HTH
Van T. Dinh
MVP (Access)



-----Original Message-----
Hi
This must be another easy one for you guys:

I am trying to read all email addresses in a table into a

string variable using "getrows".
I have searched the Internet for a few days and couldn't

get it work for me. the following
is the code I come up with. It doesn't work. It stops at

OpenRecordset saying type
missmatch.

Please help......

ad

=============================
Sub test()

Dim db As Database
Dim Lrs As Recordset
Dim LSQL As String
Dim email As Variant
Dim c As Integer
Dim strEmail As String

'Open connection to current Access database
Set db = CurrentDb()

'Create SQL statement to retrieve value from GST table
LSQL = "SELECT Contacts.[E-Mail Address] FROM

MailingList INNER JOIN Contacts ON MailingList.ContactID =
Contacts.[Contact ID];"

Set Lrs = db.OpenRecordset(LSQL)
email = Lrs.GetRows

For c = 1 To 2
strEmail = strEmail & email(c) & "; "
Next c

' Display the results.
MsgBox strEmail

Lrs.Close
Set Lrs = Nothing


End Sub


.

  #3  
Old September 22nd, 2004, 03:12 AM
ad
external usenet poster
 
Posts: n/a
Default


"Van T. Dinh" wrote in message ...
You don't need the GetRows Method. All you need to do is
to traverse the Recordset and use concatenation to append
to the strEmail as you traverse the Recordset using a loop.

Check Access Help on the MoveNext Method of the Recordset.


Thank you very much Van! It works now. However I had to dim Lrs as
object, not Recordset. If I dim Lrs as Recordset, it gives me type
mismatching error message at OpenRecordset. Why is this?

code that WORKs:
===============
Sub test()
Dim db As Database
Dim Lrs As Object '------
Dim LSQL As String
Dim strEmail As String

'Open connection to current Access database
Set db = CurrentDb()

'Create SQL statement to retrieve value from table
LSQL = "SELECT Contacts.[E-Mail Address] FROM MailingList INNER JOIN Contacts ON MailingList.ContactID = Contacts.[Contact ID];"
Set Lrs = db.OpenRecordset(LSQL)

While Not Lrs.EOF
strEmail = strEmail + Lrs![E-Mail Address] + "; "
Lrs.MoveNext
Wend

' Display the results.
MsgBox strEmail

Lrs.Close
Set Lrs = Nothing
End Sub


  #4  
Old September 22nd, 2004, 03:41 AM
ad
external usenet poster
 
Posts: n/a
Default

Thank you very much Van! It works now. However I had to dim Lrs as
object, not Recordset. If I dim Lrs as Recordset, it gives me type
mismatching error message at OpenRecordset. Why is this?


I have figured it out: set the appriate references, forgot which one,
after trying different stuff, it's working now.

Thanks again.


  #5  
Old September 22nd, 2004, 04:02 AM
Van T. Dinh
external usenet poster
 
Posts: n/a
Default

You probably have both ADO & DAO Library in the References
and the ADO has higher priority than the DAO Library.
When you dim. the Recordset without qualifier, it is
defaulted to ADO Recordset. However, you code needs DAO
Recordset and ADO Recordset / DAO Recordset are not
compatible.

Try the Dim statement:

Dim Lrs As DAO.Recordset

HTH
Van T. Dinh
MVP (Access)




-----Original Message-----
Thank you very much Van! It works now. However I had to

dim Lrs as
object, not Recordset. If I dim Lrs as Recordset, it

gives me type
mismatching error message at OpenRecordset. Why is this?

code that WORKs:
===============
Sub test()
Dim db As Database
Dim Lrs As Object '------
Dim LSQL As String
Dim strEmail As String

'Open connection to current Access database
Set db = CurrentDb()

'Create SQL statement to retrieve value from table
LSQL = "SELECT Contacts.[E-Mail Address] FROM

MailingList INNER JOIN Contacts ON MailingList.ContactID =
Contacts.[Contact ID];"
Set Lrs = db.OpenRecordset(LSQL)

While Not Lrs.EOF
strEmail = strEmail + Lrs![E-Mail Address] + "; "
Lrs.MoveNext
Wend

' Display the results.
MsgBox strEmail

Lrs.Close
Set Lrs = Nothing
End Sub


.

  #6  
Old September 22nd, 2004, 04:48 AM
ad
external usenet poster
 
Posts: n/a
Default

Thanks again


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL view of messed up action queries Kendra Running & Setting Up Queries 2 August 31st, 2004 09:53 PM
Merge data from one table into another table xpnovice General Discussion 2 June 8th, 2004 01:58 PM
Data Table Max Worksheet Functions 1 April 12th, 2004 04:12 AM
can I hide a series in a stacked bar chart but keep the series in the data table Stephen Bullen Charts and Charting 0 December 5th, 2003 10:53 AM


All times are GMT +1. The time now is 09:03 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.