Link to home
Start Free TrialLog in
Avatar of jason bradway
jason bradway

asked on

Converting Varchar Value to DataType Int

I am getting the following Microsoft Visual Basic RunTime Error '245': Conversion failed when converting the varchar value '[Forms]![MedicalHistoryPhysicalAdmissionLookupForm]![Family]' to data type int. When running the following code.  Its driving me nuts as the value being passed is 108 and the field Family is data type INT as well as I have changed the form to reflect that it is a numeric field.

strSQL = " INSERT INTO MedHistoryPhysicalAdmission ( FAMILY, AdmissionDate )"
    strSQL = strSQL & " SELECT Convert(int,'[Forms]![MedicalHistoryPhysicalAdmissionLookupForm]![Family]'), "
    strSQL = strSQL & "'[Forms]![MedicalHistoryPhysicalAdmissionLookupForm]![AdmissionDate]';"

    DoCmd.RunSQL (strSQL)

Open in new window

Avatar of Norie
Norie

Try this.
strSQL = " INSERT INTO MedHistoryPhysicalAdmission ( FAMILY, AdmissionDate )"    

strSQL = strSQL & " SELECT Convert(int,' & [Forms]![MedicalHistoryPhysicalAdmissionLookupForm]![Family] & '), "    
strSQL = strSQL & "'" & [Forms]![MedicalHistoryPhysicalAdmissionLookupForm]![AdmissionDate] & "';"

DoCmd.RunSQL (strSQL)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jason bradway

ASKER

Phew! that solved my problem with Family now its giving me a problem with AdmissionDate but that might be a database issue.  Runtime error 206:  Operand Type Clash: int is incompatible with date.
The problem is probably due to the difference in the way dates are stored in Access and SQL Server.

That's assuming the AdmissionDate is a datetime field.