Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a query (crosspost)

Status
Not open for further replies.

Atomsk

MIS
Jun 3, 2003
60
US
In an Access database, I'm trying to read the values of a field [Request ID] from a query [isOverdue] from a table [Table1] in my database [Database01]. Right now, [isOverdue] returns three records with [Request ID] values of 4, 5, and 10. I'm trying to read those values from the query's recordset and store them in a string. Code follows (this is VBScript, btw):


Dim returnString
Const strQueryName = "isOverdue"
Dim db, rs
Set db = ?????
Set rs = db.OpenRecordset(strQueryName)

Do While Not rs.eof
If returnString <> &quot;&quot; Then returnString = returnString & &quot;,&quot;
returnString = returnString & rs.Fields(&quot;Request ID&quot;).Value
RS.MoveNext
Loop

rs.Close
db.Close

returnString should now have a value of {4, 5, 10}

I don't even know whether the above will work or not, but first, I can't figure out what I'm supposed to put where Set db = ????
 
try it like this

Do While Not rs.eof
If returnString = &quot;&quot; Then
returnstring = rs.Fields(&quot;Request ID&quot;)
else
returnString = returnString & &quot;, &quot; & rs.Fields(&quot;Request ID&quot;)
end if
RS.MoveNext
Loop
 
It says that I still need to set db as something.
 
Set db = Server.CreateObject(&quot;ADODB.Connection&quot;)
db.Open &quot;<Connection string to your DB>&quot;
 
&quot;Internet Explorer Script Error&quot;
Line 73:
Error: Object required: 'Server'
Code: 0
URL: accdp://4332704/


73: Set db = Server.CreateObject(&quot;ADODB.Connection&quot;)


Thanks for the help, btw.
 
Sorry, get rid of server. it's just CreateObject, I'm thinking web app
 
Line: 74
Char: 1
Error: [Micosoft][ODBC Driver Manager] Data source name not found and no default driver specified
Code: 0
URL: accdp://4332704/

74: db.Open &quot;C:\work\database01.mdb&quot;

Man, this thing's fighting me every step of the way...
 
New Error, code so far:

Line: 75
Char: 1
Error: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

70: Dim returnString
71: Const strQueryName = &quot;isOverdue&quot;
72: Dim db, rs
73: Set db = CreateObject(&quot;ADODB.Connection&quot;)
74: db.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\work\database01.mdb&quot; & &quot;;UID=user;PWD=password&quot;
75: Set rs = db.OpenRecordset(strQueryName)
76:
77: Do While Not rs.eof
78: If returnString = &quot;&quot; Then
79: returnstring = rs.Fields(&quot;Request ID&quot;)
80: else
81: returnString = returnString & &quot;, &quot; & rs.Fields(&quot;Request ID&quot;)
82: end if
83: RS.MoveNext
84: Loop

86: rs.Close
87: db.Close
 
AHAHAHA! IT LIVES! ...though setting the recordsource is a bit different from the example above:

Dim returnString
Const strQueryName = &quot;isOverdue&quot;
Dim db, rs
Set db = CreateObject(&quot;ADODB.Connection&quot;)
db.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\work\database01.mdb&quot; & &quot;;UID=;PWD=&quot;
Set rs=db.execute(&quot;SELECT * FROM isOverdue&quot;)

Thanks a lot spazman!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top