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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

including a where clause in a vba sql 'insert into' statement 1

Status
Not open for further replies.

maggsz

Programmer
Sep 26, 2012
15
AU
how do I include a where clause in the sql 'insert into' statement:

strSql = "Insert into parts (ID, part_number) values (" & ID & ", '" & strpart(i) & "')"

the where clause I want to include is

str_part <> "A" and str_part <> "B" and str_part is not null

thanks in advance

maggsz
 
There is no WHERE clause in an INSERT INTO statement.
I'd use an If instruction in VBA, eg:
If str_part(i) <> "A" And str_part(i) <> "B" And Not IsNull(str_part(i) Then
strSql = "Insert into parts (ID, part_number) values (" & ID & ", '" & strpart(i) & "')"
...
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV
thanks so much for pointing me in the right direction.
This is what I ended up with and it worked.
I have learnt another piece of the vba sql puzzle thanks to you PHV :D

strSql = "Insert into parts (ID, part_number) values (" & ID & ", '" & strpart(i) & "')"
If str_part(i) <> "A" And str_part(i) <> "B" And Not IsNull(str_part(i) Then
currentdb.execute strSql
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top