Code chgs table in query

B

Bonnie

Hi there. Using A02 on XP. Not a programmer but love the newsgroups.
Learning alot.

Someone helped me with code that would pull the tables named like a field
[RunThisOne] on my form into a select query. Now I need to pull just one
number field (long integer) in a different query and thought I'd get brave
and try to edit what I already have. Getting an error on the line:
qryTest.SQL = strSQL noted below. Error is: "Runtime error 3141. The
SELECT statement includes a reserved word or an argument name that is
misspelled or missing, or the punctuation is incorrect." Must be the number
field called [Hours] maybe? Used the field in other code and no error like
this.

Private Sub EditHours_Click()
Dim strSQL As String
Dim dbsCurrent As Database
Dim qryTest As QueryDef

Set dbsCurrent = CurrentDb

strSQL = "SELECT "

strSQL = strSQL & [Forms]![fCensus1Conversion]![RunThisOne] &
"Revised.Hours, "

strSQL = strSQL & " FROM "
strSQL = strSQL & [Forms]![fCensus1Conversion]![RunThisOne] & "Revised "
strSQL = strSQL & "WITH OWNERACCESS OPTION;"

'MsgBox strSQL
'Debug.Print strSQL

'the name of your query goes in here
Set qryTest = dbsCurrent.QueryDefs("qCensus1EditHours")

qryTest.SQL = strSQL GETTING ERROR HERE
'Debug.Print strSQL
'other code

Set dbsCurrent = Nothing
Set qryTest = Nothing
'--------------------------------

'Uncomment the MsgBox line or add a Debug.Print strSQL line.
'Debug.Print strSQL
'It should give you the correct SQL for the value selected in the
"RunThisOne" combo box.

'Export the data
'DoCmd.RunMacro ("mCensus1.ExportRevised")
'MsgBox "Hours worked codes have been edited."

End Sub

Can anyone help? Thanks in advance for any help or advice.
 
S

SteveS

Bonnie,

Since there is only one field, remove the comma after "Revised.Hours" in
this line:

strSQL = strSQL & [Forms]![fCensus1Conversion]![RunThisOne] &
"Revised.Hours, "


HTH
 

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