Error in query referring to Combo Box

P

PaulSchueller

I am very new to using VBA to build forms and am having a problem. I
trying to embed a query within a public sub routine. The goal of this
query is to use an alphanumeric code entered into a combo box on the
form to retrieve an associated ID within a table. The bound column of
the combo box is text. I have used the following code:

Public Sub GetSturID(intSturID As Integer)
Dim rsSturID As ADODB.Recordset
Set rsSturID = New ADODB.Recordset
rsSturID.Open "SELECT tblSturg.SturgID FROM tblSturg WHERE
(tblSturg.PIT = '" & cmbPIT.Value & "')" _
& "GROUP BY tblSturg.SturgID", CurrentProject.Connection,
adOpenKeyset, adLockOptimistic, adCmdTable
rsSturID.MoveFirst
intSturID = rsSturID("SturgID")
rsSturID.Close
End Sub

Error Reads: Syntax error in FROM Clause. This querying technique I
have used before, but not with strings and I
am not sure what the problem is. I have tried many things, but to no
avail. Your help is much appreciated.
 
R

ruralguy via AccessMonster.com

Put your SELECT string in a String variable and then show it in a MsgBox
before you use it. You probably have places where an extra space in the
string would help.
 
P

PaulSchueller

Put your SELECT string in a String variable and then show it in a MsgBox
before you use it. You probably have places where an extra space in the
string would help.







--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted viahttp://www.accessmonster.com

It ended up being that the adCmdTable at the end of the select
statement was not needed.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top