systematic
Registered User.
- Local time
- Today, 10:40
- Joined
- Sep 13, 2005
- Messages
- 28
Hi there,
I have a form that uses ADO to create a new record in a table. I have used the form successfully throughout the development of my database (with Access 2003), but am now having trouble with earlier versions.
I get the following error -
-2147352571 "Type mismatch"
when attempting to write to the database. The error occurs when I am trying to write the value from a control, and the value is 'Nothing' or 'Null'.
Here is my code -
Set rs = New ADODB.Recordset
rs.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= ........../customer.mdb;"
rs.Open "tblCustomers", , adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.AddNew
.Fields("Customer_Firstname") = Me.txtFirstName.Value
.Fields("Customer_Surname") = Me.txtSurname.Value
.Fields("Customer_Type") = Me.cboCusType.Value
.Fields("MDL") = Me.txtMDL.Value
.Fields("MVL") = Me.txtMVL.Value
.Fields("Address") = Me.txtAddress.Value
.Fields("PhoneH") = Me.txtHomePh.Value
.Fields("PhoneW") = Me.txtBusPh.Value
.Fields("Mobile") = Me.txtMobile.Value
.Fields("Fax") = Me.txtFax.Value
.Fields("Email") = Me.txtEmail.Value
.Fields("Suburb") = Me.txtSuburb.Value
.Fields("State") = Me.txtState.Value
.Fields("Postcode") = Me.txtPostcode.Value
.Fields("Contact") = Me.txtContact.Value
CusNo = .Fields("Customer_No")
.Update
End With
rs.Close
Set rs = Nothing
StrSQL = "UPDATE tblEnquiries SET Customer_No =" & Chr(34) & CusNo & Chr(34)
StrSQL = StrSQL & " WHERE ID = " & Forms!frmEnquiry!txtAns.Value & ";"
CurrentDb.Execute StrSQL
I have tried to get around this with the following method...
Dim Suburb As String
Suburb = Me.txtSuburb & ""
.Fields("Suburb") = Suburb
This then generates run-time error 91 (Object variable or with variable not set).
I should mention that both the 'First Name' and 'Surname' textboxes have input masks - but do not see how this could cause my problem.
I am at a complete loss to what is going wrong.
Could anyone help me out please?
Thanks
Robert
EDIT: Just some reading I have come across....apparently the problem may to do with Access 2000/2002 using the ADO as default instead of DAO...I have read that this may cause some problems. I should mention that changing my code to reference DAO is not really an option due to time constraints (I am near the end of this project) - but NEXT TIME!
I have a form that uses ADO to create a new record in a table. I have used the form successfully throughout the development of my database (with Access 2003), but am now having trouble with earlier versions.
I get the following error -
-2147352571 "Type mismatch"
when attempting to write to the database. The error occurs when I am trying to write the value from a control, and the value is 'Nothing' or 'Null'.
Here is my code -
Set rs = New ADODB.Recordset
rs.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= ........../customer.mdb;"
rs.Open "tblCustomers", , adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.AddNew
.Fields("Customer_Firstname") = Me.txtFirstName.Value
.Fields("Customer_Surname") = Me.txtSurname.Value
.Fields("Customer_Type") = Me.cboCusType.Value
.Fields("MDL") = Me.txtMDL.Value
.Fields("MVL") = Me.txtMVL.Value
.Fields("Address") = Me.txtAddress.Value
.Fields("PhoneH") = Me.txtHomePh.Value
.Fields("PhoneW") = Me.txtBusPh.Value
.Fields("Mobile") = Me.txtMobile.Value
.Fields("Fax") = Me.txtFax.Value
.Fields("Email") = Me.txtEmail.Value
.Fields("Suburb") = Me.txtSuburb.Value
.Fields("State") = Me.txtState.Value
.Fields("Postcode") = Me.txtPostcode.Value
.Fields("Contact") = Me.txtContact.Value
CusNo = .Fields("Customer_No")
.Update
End With
rs.Close
Set rs = Nothing
StrSQL = "UPDATE tblEnquiries SET Customer_No =" & Chr(34) & CusNo & Chr(34)
StrSQL = StrSQL & " WHERE ID = " & Forms!frmEnquiry!txtAns.Value & ";"
CurrentDb.Execute StrSQL
I have tried to get around this with the following method...
Dim Suburb As String
Suburb = Me.txtSuburb & ""
.Fields("Suburb") = Suburb
This then generates run-time error 91 (Object variable or with variable not set).
I should mention that both the 'First Name' and 'Surname' textboxes have input masks - but do not see how this could cause my problem.
I am at a complete loss to what is going wrong.
Could anyone help me out please?
Thanks
Robert
EDIT: Just some reading I have come across....apparently the problem may to do with Access 2000/2002 using the ADO as default instead of DAO...I have read that this may cause some problems. I should mention that changing my code to reference DAO is not really an option due to time constraints (I am near the end of this project) - but NEXT TIME!

Last edited: