Triscuit
Registered User.
- Local time
- Today, 06:33
- Joined
- Jul 20, 2010
- Messages
- 27
Code for a "Search button", lookups the record if not found adds the record to the table.
I don't recognize where the 3421 Data type conversion error comes from.
Private Sub Search_Click()
On Error GoTo Error_Search_Click:
Dim db As DAO.Database
Dim rstCalibrationGroup As DAO.Recordset
Const conFilter As String = " & Me.cboFilter & "
Set db = CurrentDb
Set rstCalibrationGroup = db.OpenRecordset("tblCalibrationGroup")
If IsNull(Me!cboFilter) Then
GoTo Finish
End If
rstCalibrationGroup.OpenRecordset "Select * from tblCalibrationGroup WHERE txtCalibGroup = conFilter"
'Then, if the recordset comes back with no records, you know you have to add:
If rstCalibrationGroup.EOF Then
rstCalibrationGroup.AddNew
rstCalibrationGroup("txtCalibGroup").Value = Me!cboFilter
Else
Me!LstSearch.RowSource = "SELECT txtLabNum FROM tblCalibrationGroup WHERE [txtCalibGroup] = '" & Me!cboFilter & "' "
End If
Finish:
Exit Sub
Exit_Search_Click:
Exit Sub
Error_Search_Click:
MsgBox Err.Number & Err.Description
Resume Exit_Search_Click
End Sub
I don't recognize where the 3421 Data type conversion error comes from.
Private Sub Search_Click()
On Error GoTo Error_Search_Click:
Dim db As DAO.Database
Dim rstCalibrationGroup As DAO.Recordset
Const conFilter As String = " & Me.cboFilter & "
Set db = CurrentDb
Set rstCalibrationGroup = db.OpenRecordset("tblCalibrationGroup")
If IsNull(Me!cboFilter) Then
GoTo Finish
End If
rstCalibrationGroup.OpenRecordset "Select * from tblCalibrationGroup WHERE txtCalibGroup = conFilter"
'Then, if the recordset comes back with no records, you know you have to add:
If rstCalibrationGroup.EOF Then
rstCalibrationGroup.AddNew
rstCalibrationGroup("txtCalibGroup").Value = Me!cboFilter
Else
Me!LstSearch.RowSource = "SELECT txtLabNum FROM tblCalibrationGroup WHERE [txtCalibGroup] = '" & Me!cboFilter & "' "
End If
Finish:
Exit Sub
Exit_Search_Click:
Exit Sub
Error_Search_Click:
MsgBox Err.Number & Err.Description
Resume Exit_Search_Click
End Sub