|
-
Catfish
Running a Query in VB within Access [solved]
I need to run the following query in VB, but it goes in an event procedure for a form button in Access. It's looking up a language abbreviation given the language name.
Code:
SELECT abbreviation FROM languages WHERE name = Me.languageForm
Where languageForm contains the language name.
Thanks
Last edited by webraycer; 07-18-2005 at 09:45 AM.
-
Mako Shark
If you are talking about using an ADODB.Recordset object you would just do something like this:
Dim rstRS as New ADODB.Recordset
rstRS.Open "Put query here", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
Core 2 Duo w Radeon 4850, Droid Phone, Mits HD1000U projector
-
Catfish
 Originally Posted by Paladyr
If you are talking about using an ADODB.Recordset object you would just do something like this:
Dim rstRS as New ADODB.Recordset
rstRS.Open "Put query here", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
"No value given for one or more required parameters"
That's what I see in an alert window for the rstRS.Open line.
Also, is this syntax correct to read the results of a query:
Code:
Me.filename = Me.filename & rstRS.Fields.Item(0)
-
Mako Shark
 Originally Posted by webraycer
"No value given for one or more required parameters"
That's what I see in an alert window for the rstRS.Open line.
Also, is this syntax correct to read the results of a query:
Code:
Me.filename = Me.filename & rstRS.Fields.Item(0)
That's not correct. You can read the results by either:
rstRS("Field_Name")
or
rstRS!Field_Name
if you have a space
rstRS![Field Name]
plus depending on what you are assigning the value to you may need to convert the field to a string, number, whatever...
Dim str1 as String
str1 = CStr(rstRS("Field_Name"))
Core 2 Duo w Radeon 4850, Droid Phone, Mits HD1000U projector
-
Catfish
Thanks -- but my rstRS.Open line is still broken with the same error.
-
Catfish
It works now -- I forgot to put single quotes around a value in the query -- I had "WHERE name=targetname" instead of "WHERE name='targetname'"
Why that gave me the error I got I have no idea -- most programming languages give a query syntax error.
-
Mako Shark
 Originally Posted by webraycer
It works now -- I forgot to put single quotes around a value in the query -- I had "WHERE name=targetname" instead of "WHERE name='targetname'"
Why that gave me the error I got I have no idea -- most programming languages give a query syntax error.
when you are opening recordsets, you will only get errors that the recordset can generate, rather than an error about interpreting the SQL statement. Glad it works!
Core 2 Duo w Radeon 4850, Droid Phone, Mits HD1000U projector
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|