N
NHiorns
I was given help over the last couple of weeks with the
following script to update a boolean field using a from
and to selection (using a combobox). This now works, with
many thanks to SteveS and Marshall Barton.
However, the customer now wants to do the same on another
database, but on this occasion the StartNum and EndNum
field is now alpha-numeric and get the following error;
Syntax error (missing operator) in query expression ....
Original script below. Using Access 2000.
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim tmp As Integer
Dim strSQL As String
'StartNum and EndNum must be numeric
If Not IsNumeric(StartNum) Then
StartNum = ""
StartNum.SetFocus
MsgBox "Enter a number between 1 and 8000"
Exit Sub
End If
If Not IsNumeric(EndNum) Then
EndNum = ""
EndNum.SetFocus
MsgBox "Enter a number between 1 and 8000"
Exit Sub
End If
' EndNum must be greater than StartNum
If EndNum < StartNum Then
tmp = EndNum
EndNum = StartNum
StartNum = tmp
End If
'set all records to false
'comment out the next line if you don't want to clear
previous selections
CurrentDb.Execute "UPDATE Table2 SET Table2.Selected =
False;"
'now set record that are between Start and End to true
strSQL = "UPDATE Labels SET Labels.Selected = -1 "
strSQL = strSQL & " WHERE Labels.ID >= " & [Forms]!
[Label]![StartNum]
strSQL = strSQL & " And Labels.ID <= " & [Forms]!
[Label]![EndNum] & ";"
'now do it!!
CurrentDb.Execute strSQL
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
following script to update a boolean field using a from
and to selection (using a combobox). This now works, with
many thanks to SteveS and Marshall Barton.
However, the customer now wants to do the same on another
database, but on this occasion the StartNum and EndNum
field is now alpha-numeric and get the following error;
Syntax error (missing operator) in query expression ....
Original script below. Using Access 2000.
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim tmp As Integer
Dim strSQL As String
'StartNum and EndNum must be numeric
If Not IsNumeric(StartNum) Then
StartNum = ""
StartNum.SetFocus
MsgBox "Enter a number between 1 and 8000"
Exit Sub
End If
If Not IsNumeric(EndNum) Then
EndNum = ""
EndNum.SetFocus
MsgBox "Enter a number between 1 and 8000"
Exit Sub
End If
' EndNum must be greater than StartNum
If EndNum < StartNum Then
tmp = EndNum
EndNum = StartNum
StartNum = tmp
End If
'set all records to false
'comment out the next line if you don't want to clear
previous selections
CurrentDb.Execute "UPDATE Table2 SET Table2.Selected =
False;"
'now set record that are between Start and End to true
strSQL = "UPDATE Labels SET Labels.Selected = -1 "
strSQL = strSQL & " WHERE Labels.ID >= " & [Forms]!
[Label]![StartNum]
strSQL = strSQL & " And Labels.ID <= " & [Forms]!
[Label]![EndNum] & ";"
'now do it!!
CurrentDb.Execute strSQL
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub