H
HRE
I am attempting to edit the criteria of a query via code. The user will
provide the name of the query to edit. The query will contain a common
field called CtyNum. On command button click event I want to change the
criteria for the CtyNum field to reference a textbox value on my form.
The data type for the CtyNum field is Number. My code:
Dim DB As DAO.Database
Dim QD As QueryDef
Dim QN As String
Dim strSQL As String
Dim strSQL1 As String
Me.UFQryName.SetFocus
QN = Me.UFQryName.Text
Set DB = CurrentDb()
Set QD = DB.QueryDefs(QN)
With QD
strSQL = .SQL
strSQL1 = Left(strSQL, InStr(1, strSQL, "Where") - 1)
strSQL = strSQL1 & "Where CtyNum=" & Me.UFCtyNum
.SQL = strSQL
End With
I receive this error message:
Run-time error '3075':
Syntax error (missing operator) in query expression 'CtyNum='.
The debugger goes to this line of code (right before the End With):
.SQL = strSQL
Any help in figuring this out would be appreciated.
provide the name of the query to edit. The query will contain a common
field called CtyNum. On command button click event I want to change the
criteria for the CtyNum field to reference a textbox value on my form.
The data type for the CtyNum field is Number. My code:
Dim DB As DAO.Database
Dim QD As QueryDef
Dim QN As String
Dim strSQL As String
Dim strSQL1 As String
Me.UFQryName.SetFocus
QN = Me.UFQryName.Text
Set DB = CurrentDb()
Set QD = DB.QueryDefs(QN)
With QD
strSQL = .SQL
strSQL1 = Left(strSQL, InStr(1, strSQL, "Where") - 1)
strSQL = strSQL1 & "Where CtyNum=" & Me.UFCtyNum
.SQL = strSQL
End With
I receive this error message:
Run-time error '3075':
Syntax error (missing operator) in query expression 'CtyNum='.
The debugger goes to this line of code (right before the End With):
.SQL = strSQL
Any help in figuring this out would be appreciated.