You want to learn as much as possible because it will help you to ask the correct questions. It will also help to understand strings as they get more and more complicated because of validation.
When you build criteria for a WHERE clause you want to do data validation. This is why I recommended using VBA. It may be beneficial to use VBA to validate data before adding it to your WHERE clause.
The code you provided is in the correct spirit. For starters you may want to make sure that you have a value in a control before you try to initialize your variable with it.
Code:
If Not IsNull([Forms]![repairs]![carnumber]) Then
carnumberint = [Forms]![repairs]![carnumber]
End If
If Not IsNull([Forms]![repairs]![invoicenumber]) Then
invoicenumberint = [Forms]![repairs]![invoicenumber]
End If
Integers can not accept null. So you will want to test for that. It can happen if a user decides to erase the value in the control.
Here is another approach to testing for null. If a control was null then your variable will = 0.
Code:
carnumberint = 0
carnumberint = Nz([Forms]![repairs]![carnumber])
invoicenumberint = 0
invoicenumberint = Nz([Forms]![repairs]![invoicenumber])
THe following code does not usually go into a single procedure but this would be an example of adding to a SELECT statement after doing data validation.
Code:
Dim strSQL As String
Dim strWhere As String
strWhere = "WHERE [PrimaryKey] >0" 'Start your WHERE clause with criteria that will always return all of the records
'This alows you to concatenate additional criteria to the existing WHERE clause
strSQL = "Select * FROM [repairstable] " & strWhere 'This will be your base SELECT query
'For now, we are done with strWhere. Initialize to empty string so we can build onto it again
strWhere = ""
'Now validate your data in the various controls and add to your base SELECT query
If Not IsNull([Forms]![repairs]![invoicenumber]) And Not IsNull([Forms]![repairs]![carnumber]) Then
strWhere = (strWhere & " AND ") & "CarNumber = " & carnumberint & " OR invoicenumber = " & invoicenumberint
'save the Between operator for last - personal preference
If Not IsNull([Forms]![repairs]![StartDate]) And Not IsNull([Forms]![repairs]![StartDate]) Then 'Make sure we have dates for each side of BETWEEN
strWhere = (strWhere & " AND ") & "[importdate] BETWEEN #" & [Forms]![repairs]![StartDate] & "# AND #" & [Forms]![repairs]![StartDate] & "#"
Else
MsgBox "Please provide a date in each of the date fields"
Exit Sub 'Abort mission until after user popolates date controls
End If
'Now that strWhere may or may not have changed, concatenate to your strSQL
strSQL = strSQL & strWhere