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.
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.
>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
[quoted text clipped - 18 lines]
>am not sure what the problem is. I have tried many things, but to no
>avail. Your help is much appreciated.

Signature
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.
PaulSchueller@gmail.com - 27 Oct 2007 15:07 GMT
On Oct 26, 2:23 pm, "ruralguy via AccessMonster.com" <u12102@uwe>
wrote:
> 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
[quoted text clipped - 29 lines]
>
> Message posted viahttp://www.accessmonster.com
It ended up being that the adCmdTable at the end of the select
statement was not needed.
Thanks
ruralguy - 27 Oct 2007 15:46 GMT
Thanks for posting back with your success.
>On Oct 26, 2:23 pm, "ruralguy via AccessMonster.com" <u12102@uwe>
>wrote:
[quoted text clipped - 7 lines]
>statement was not needed.
>Thanks

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