Microsoft Access VBA INSERT SQL statement -
i have created database within microsoft access , form.
 have button attached form , when it's clicked want insert new record table customerheader.
 there 4 fields within table 1 being autonumber.  in sql statement, don't include ordernumber since autofield.
 when try click button , on click event executed, error saying microsoft access cannot append records in append query.  
any ideas, have looked everywhere , have not been able find solution.
private sub addorder_click()     dim mysql string     dim rownum integer     dim reccount long     dim ordernumber long     dim mybool boolean       dim todaydate date      todaydate = cdate(date)      mybool = false       msgbox todaydate      rownum = form.currentrecord     rownum = cint(rownum - 1)        'docmd.gotorecord , , acnewrec     mysql = "insert orderheader (orderdate,custnumber,printed) values (" & todaydate & "," & rownum & "," & mybool & ")"      docmd.runsql mysql      me!ordernum.requery      
you don't have around - use iso sequence format of string expression date value:
mysql = "insert orderheader (orderdate,custnumber,printed) values (#" & format(todaydate, "yyyy\/mm\/dd") & "#," & rownum & "," & mybool & ")"   however, it's today, use:
mysql = "insert orderheader (orderdate,custnumber,printed) values (date()," & rownum & "," & mybool & ")"      
Comments
Post a Comment