Insert Into SQL Statment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nothing

    #1

    Insert Into SQL Statment

    I am trying to use the sql INSERT INTO statement to add a new record.

    This is the SQL statement:
    sql = "INSERT INTO tblpatients(bbi d, patientname, orderdate, ordertime,
    mrnumber, sex, age, drawnby, drawnbytime, doctor, dob, location,
    type-r-h, donortype-r-h, componet, antibody, unitnum, expdate, coombs,
    crossmatch, rhogam, unitnumber2, expdate2, fetal, commanet) VALUES
    ('bid', 'ptname', 'orddte', 'ordtime', 'mrnum', 'ptsex', 'ptage',
    'drawby', 'drawbytime', 'doc', 'ptdob', 'loc', 'typerh', 'dnrtype',
    'compo', 'antibdy', 'unitnumber', 'expdte', 'combs', 'crsmtch', 'rhogm',
    'unitnumber2', 'expdte2', 'baby', 'comments')"

    I then use the following command to run it.
    DoCmd.RunSQL sql

    What this is doing is adding a new record to the table and then printing
    a report based on the new record.
    I am not very good with VBA so this was the best I could come up with.
    I get a SQL syntax error when I run it. I tried the way the help in
    MS-Access should me but that did not work either.
    Ayone have any ideas?

    Michael Charney

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Rick Brandt

    #2
    Re: Insert Into SQL Statment

    Nothing wrote:[color=blue]
    > I am trying to use the sql INSERT INTO statement to add a new record.
    >
    > This is the SQL statement:
    > sql = "INSERT INTO tblpatients(bbi d, patientname, orderdate,
    > ordertime, mrnumber, sex, age, drawnby, drawnbytime, doctor, dob,
    > location, type-r-h, donortype-r-h, componet, antibody, unitnum,
    > expdate, coombs, crossmatch, rhogam, unitnumber2, expdate2, fetal,
    > commanet) VALUES ('bid', 'ptname', 'orddte', 'ordtime', 'mrnum',
    > 'ptsex', 'ptage', 'drawby', 'drawbytime', 'doc', 'ptdob', 'loc',
    > 'typerh', 'dnrtype', 'compo', 'antibdy', 'unitnumber', 'expdte',
    > 'combs', 'crsmtch', 'rhogm', 'unitnumber2', 'expdte2', 'baby',
    > 'comments')"
    >
    > I then use the following command to run it.
    > DoCmd.RunSQL sql
    >
    > What this is doing is adding a new record to the table and then
    > printing a report based on the new record.
    > I am not very good with VBA so this was the best I could come up with.
    > I get a SQL syntax error when I run it. I tried the way the help in
    > MS-Access should me but that did not work either.
    > Ayone have any ideas?[/color]

    Where are those VALUES items coming from? You are attempting (for example)
    to insert the string literal "orddte" into a date field (assuming OrderDate
    is a Date field). Did you intend those to be variable names? If so you
    have to delimit the SQL string so that the variables are outside of the
    quotes. This will cause the constructed statement to include the *values*
    of the variables rather than the names of the variables. In addition, you
    would need to add single quotes around the string values, pound delimiters
    (#) around the dates, and no delimiter around the numeric values for it to
    work.


    --
    I don't check the Email account attached
    to this message. Send instead to...
    RBrandt at Hunter dot com


    Comment

    Working...