Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT STATEMENT

Status
Not open for further replies.

Sarah28

IS-IT--Management
Aug 6, 2000
16
US
When I save my purchase order(based on purchase order table) I would like to add a new record to my shipping table. The following code gives me an "Invalid use of Null" error. My shipping table has four fields - ID, MachineID, Ship Date, Complete. ID is an autonumber ID field, and I want shipping date to remain null. The following is my code...Can anyone help me?

Dim db As Database
Dim qdf As QueryDef
Dim rst As Recordset
Dim str As String
Dim txtID As String

txtID = Me!txtID

Set db = CurrentDb

str = "INSERT INTO dbo_Shipping " _
& "(MachineID, Complete) " _
& "VALUES(" & Me.txtID & ",1)"

Set qdf = db.CreateQueryDef("", str)

qdf.Execute

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
 
is this what the code says?
_
& "VALUES(" & Me.txtID & ",1)"

Good luck and may God bless.
 
if the error occurs on the line where you create the string then 'Me.txtID' is null. Put a breakpoint on the line and test it for null. Also you shouldn't really create a variable that has the same name as a control on your form. And now that I look at your code again I think I see the problem. In the line that says
Code:
txtID = Me!txtID
your are using !. This makes reference to the field called txtID in the forms' recordset not the textbox txtID. I'm presuming that the field name in the table is not txtID but rather ID or some such. If this is so then this is probably where the Invalid use of Null is. Use Me.txtID instead of Me!txtID.
Sorry for being so long winded about something so simple. ;-) Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top