problems on insert statement

  • Thread starter enrico via AccessMonster.com
  • Start date
E

enrico via AccessMonster.com

why does my insert statement behind my button is working for a moment then
gives an error then work again then gives an error. the latest error is:

data type mismatch in criteria expression

i can't determine what's the problem because today it'll work and tom. it
might not. this is the code i used anyway:

Dim db As DAO.Database
Dim strSql As String

strSql = ("INSERT INTO tblGenInfo(Lastname, " & _
" Firstname, " & _
" MI, Age, " & _
" Sex, " & _
" CivilStatus, " & _
" MembershipCategory, " & _
" MembershipType, " & _
" Address, " & _
" Hospital, " & _
" DateAdmitted, " & _
" DateDischarge, " & _
" DateofSurvey) " & _
"VALUES ('" & Me.txtLastName & "', " & _
" '" & Me.txtFirstname & "', " & _
" '" & Me.txtMI & "', '" & Me.txtAge & "', " & _
" '" & Me.cboSex & "', " & _
" '" & Me.cboCivilStatus & "', " & _
" '" & Me.cboMemCategory & "', " & _
" '" & Me.cboMemClass & "', " & _
" '" & Me.txtAddress & "', " & _
" '" & Me.cboHospital & "', " & _
" '" & Me.txtDateAdmitted & "', " & _
" '" & Me.txtDateDischarged & "', " & _
" '" & Me.txtDateofSurvey & "')")

Set db = CurrentDb
db.Execute strSql, dbFailOnError
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're treating all the data as strings. Numbers do not require
delimiting quotes. Dates, in USA format (m/d/yy), require the pound
sign (#) as the delimiter. Are you sure the values in the ComboBoxes
are all strings or are some of them numbers? If Numbers remove the
quote delimiters in the VALUES clause.

You could make life easier if you just bound the form to the tblGenInfo
table and assigned the controls to the appropriate columns. That's one
of the advantages of using Access.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSZTO3IechKqOuFEgEQKx2ACbBW9jVhajCZ/cwNfSKvVYk/J1IOMAoIE7
NII4tuJ7eaMhtAFQK2yueqnO
=5N3H
-----END PGP SIGNATURE-----
 
E

enrico via AccessMonster.com

i already remove the delimiting quote on my number fields. but there's still
an error, a new one:

too few parameters. expected 1.

what does it mean?
 
J

John Spencer

Usually it means that you have misspelled something or that you are
trying to pass a string value (without quotes) into a field and SQL is
attempting to interpret that string value as the name of a field or
parameter.


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top