SQL Syntax Problem

D

DS

I'm trying to run this and it doesn't seem to be working It works fine
until I put the LineID into it. I need the DMax statement to check the
LineID if its null, if not then make it +1

CurrentDb.Execute "Insert into SalesDetails (LineID,SalesID,ItemID)
Values(Nz(DMax(LineID, SalesDetails), 0) + 1 ," & Me.SalesID & "," &
Me.List215.Column(0) & "))"



Thanks
DS
 
S

SusanV

Assuming you have already dimmed and instantiated LineID:

If IsNull(LineID) then
LineID = '1'
Else
LineID = LineID + 1
End If

CurrentDb.Execute "Insert into SalesDetails (LineID,SalesID,ItemID)
Values(LineID, " & Me.SalesID & "," &
Me.List215.Column(0) & "))"
 
V

Van T. Dinh

Try:

CurrentDb.Execute "Insert into SalesDetails (LineID,SalesID,ItemID) Values
(" & _
Nz(DMax("LineID", "SalesDetails"), 0) + 1 & _
", " & Me.SalesID & ", " & Me.List215.Column(0) & ")"
 

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

Similar Threads

Loop Question 2
No Records Then 4
Loop Returning One Value 6
DMax Problem 3
Run Time error when trying to use DMax on a line value 6
SQL Woes 7
SQL Syntax Error 3
It Says NO CURRENT RECORD 2

Top