I am getting the error message 'type mismatch' at line 22 when running the code below:
It is worth noting that the field txtID is just a plain text box with an input mask that allows a maximum of 3 characters but no less that 2.
I can't understand it.... I've even replaced the SQL at line 21 and hard coded a two character ID such as....
but i still get the same error message. I don't know what i'm doing wrong as i've definately done something like this before.
Any help would be much appreciated!!
Code:
Private Sub cmdSave_Click()
'On Error GoTo Err_cmdFacilitatorSave_Click
'Check flag status
If Me!txtFlag = 1 Then '(New)
'----------------------------------------------------------------------------------------------------
MsgBox "New Facilitator"
Me!txtID.SetFocus
'Check to make sure the user has entered a facilitator ID
If Me!txtID.Text = "" Then 'If they haven't.....
MsgBox "You must ensure that you enter a facilitator ID (usually initials)."
Me!txtID.SetFocus
Else 'If they have.....
Dim dbsCTrack
Dim rstNewFacil As Recordset
Dim sqlNewFacil As String
MsgBox Me.txtID
Set dbsCTrack = CurrentDb
sqlNewFacil = "SELECT * FROM tblFacilitator WHERE tblFacilitator.facil_id = '" & Me.txtID & "'"
[B]Set rstNewFacil = dbsCTrack.OpenRecordset(sqlNewFacil)[/B]
MsgBox "Test"
'Check to see if the facilitator already exists
If rstNewFacil.RecordCount = 0 Then 'If they don't.....
rstNewFacil.AddNew
rstNewFacil(0) = Me.txtID
rstNewFacil(1) = Me.txtName
rstNewFacil(2) = Me.txtAdd1
rstNewFacil(3) = Me.txtAdd2
rstNewFacil(4) = Me.txtAdd3
rstNewFacil(5) = Me.txtAdd4
rstNewFacil(6) = Me.txtPcode
rstNewFacil(7) = Me.txtPhone
rstNewFacil(8) = Me.txtEmail
rstNewFacil.Update
rstNewFacil.Close
MsgBox Me.txtID & " - " & Me.txtName & " has been created as a facilitator."
Else 'If they do.....
MsgBox "A facilitator already exists with the ID: " & Me!txtID & ". Please enter a different ID."
Me!txtID.SetFocus
End If
End If
ElseIf Me!txtFlag = 2 Then '(Edit)
'If statement continues.....
I can't understand it.... I've even replaced the SQL at line 21 and hard coded a two character ID such as....
Code:
sqlNewFacil = "SELECT * FROM tblFacilitator WHERE tblFacilitator.facil_id = 'FT'"
Any help would be much appreciated!!
Comment