Yo. I am making a project in vb6. The backend is MS Access 2003. Data is entered into the form and stored in the database table.

The code:

With cnct

.BeginTrans

.Execute "INSERT INTO Employee_Info (EI_CNIC, EI_FirstName, EI_LastName, EI_Gender, EI_Birthdate, EI_Country, EI_Language, EI_MaritalStat, EI_Education, EI_Designation, EI_Salary, EI_ResdAddress, EI_ResdContact, EI_Cellphone, EI_EmailID, EI_PostalCode, EI_FaxCode, EI_Supervisor, EI_DateHired)" & "VALUES('" & txtCNIC.Text & "', '" & txtFirstName.Text & "', '" & txtLastName.Text & "', '" & cboGender.Text & "', '" & lblBirthdate.Caption & "', '" & cboCountry.Text & "', '" & txtLanguage.Text & " ', '" & cboMaritalStatus.Text & "', '" & txtEducation.Text & "', '" & txtDesignation.Text & "', '" & txtSalary.Text & "', '" & txtResdAddress.Text & "', '" & txtResdContact.Text & "', '" & txtCellPhone.Text & "', '" & txtEmailID.Text & "', '" & txtPostalCode.Text & "', '" & txtFaxCode.Text & "', '" & txtSupervisor.Text & "', '" & txtDateHired.Text & "')"

.CommitTrans

End With

In the database table:
these fields are number data type: EI_CNIC, EI_ResdContact, EI_Cellphone, EI_PostalCode, EI_FaxCode.
the rest are text data type

I get a data type mismatch in criteria expression error. I researched a lot on the net and the most common solution offered is to remove the single inverted comma(') around the fields that are not string data types. It doesnt work in my case.
A bit of guidance would be great.

Fix the following -

'" & txtLanguage.Text & " ',
TO
'" & txtLanguage.Text & "',

Also send a messagebox for each textbox value to make sure that the correct values is returned i.e. a string, an integer etc. and that no empty values is in there somewhere. Once tested and you know that all data is returning correctly, make sure about empty spacing as in my code above.

I removed the empty spacing. And it worked. It didnt even need the message box. I feel like a loser now. -.- Thanks for the help.

:) We were all there one or another time. It happens and the worse part is that we tend to stare ourselves blind against the code not seeing the error. :)

Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.