Rabu, 29 Juni 2011

[MS_AccessPros] Data type mismatch in lookup form

 

I have a main form with a combobox called RoomTypeID. When the user double click on the RoomTypeID it should open a form called frmLkpRoomType which allows the user to add or modify Room Type items. This is code behind the double click event:

Private Sub RoomTypeID_DblClick(Cancel As Integer)
Dim rs As DAO.Recordset
Dim strWhere As String
Const strcTargetForm = "frmLkpRoomType"

'Set up to search for the current Room Type.
If Not IsNull(Me.RoomTypeID) Then
strWhere = "RoomTypeID = """ & Me.RoomTypeID & """"
End If

'Open the editing form.
If Not CurrentProject.AllForms(strcTargetForm).IsLoaded Then
DoCmd.OpenForm strcTargetForm
End If
With Forms(strcTargetForm)

'Save any edits in progress, and make it the active form.
If .Dirty Then .Dirty = False
.SetFocus
If strWhere <> vbNullString Then
'Find the record matching the combo.
Set rs = .RecordsetClone
rs.FindFirst strWhere
If Not rs.NoMatch Then
.Bookmark = rs.Bookmark
End If
Else
'Combo was blank, so go to new record.
RunCommand acCmdRecordsGoToNew
End If
End With
Set rs = Nothing

End Sub

The strWhere is coming back with strWhere="RoomTypeID ="1""

But its erroring out on the rs.FindFirst strWhere with a Data Type Mismatch.

This snippet I found on Allen Browne site.

The form frmLkpRoomType contains two fields called RoomTypeID and RoomTypeName

Any Ideas?

Thanks,
Art Lorenzini

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar