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

SQL Insert Into Where Syntax

Status
Not open for further replies.

DeoM

Programmer
Jul 3, 2004
49
PH
Help, Please tell me whats wrong with my SQL syntax; am getting a data mismatch error.
POCreation is a blank table where I want to append data from
POparts for only a certain PO number
POnumber is Long Integer
strPOnumber is a variable where i input the POnumber i want to append.


DoCmd.RunSQL "INSERT INTO POCreation SELECT * FROM [POparts] WHERE [POnumber] = '" & strPOnumber & "'"
 
Single quotes are used on text fields, for numerics you don't need them:

[tt]DoCmd.RunSQL "INSERT INTO POCreation SELECT * FROM [POparts] WHERE [POnumber] = " & strPOnumber[/tt]

Roy-Vidar
 
How are ya DeoM . . . . .

You need to specifiy the fields and [purple]on a one to one basis[/purple]. If the field order is different between the tables its easy to get a mismatch error.

Something like:
Code:
[blue]DoCmd.RunSQL "INSERT INTO POCreation [purple][b](field1,field2 ...)[/b][/purple] SELECT [purple][b]field1,field2 ...[/b][/purple] FROM [POparts] WHERE [POnumber] = '" & strPOnumber & "'"[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan,
They are identical tables.
 
Is it just me?

SQL Where Clause has the following parts

WHERE ( )

Inside the above you need this syntax

((Field) = value)

So yours would be
Code:
"WHERE (((PONumber) = " & strPoNumber & "))"

Want the best answers? See FAQ181-2886
 
redapples, the qbe gets carried away with brackets and more often than not they can be stripped out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top