INSERT INTO using field names from a form (1 Viewer)

ECCS01

New member
Local time
Today, 14:01
Joined
Sep 28, 2006
Messages
1
Hi everyone,

I am using the following code but - it isn't putting the values of the form fields in my table.

Can you help me with the correct syntax?

Many thanks!

Dim dbs As DAO.Database
Dim strSQL As String

Set dbs = OpenDatabase("v:\lab\sdawOrderID\sdaw.mdb")

DoCmd.RunSQL "INSERT INTO Customer(Name, BillAddressAddr1, BillAddressAddr2) VALUES('" & [Forms].[AddCustomer].[Name] & "','" & [Forms].[AddCustomer].[Address1] & "','" & [Forms].[AddCustomer].[Address2] & "');"


dbs.Execute strSQL, dbFailOnError


dbs.Close
 

SQL_Hell

SQL Server DBA
Local time
Today, 22:01
Joined
Dec 4, 2003
Messages
1,360
Hi,

wrong forum, this is for SQL server

But however change to this....


Dim dbs As DAO.Database
Dim strSQL As String
Dim name,add1,add2 as string

name = [Forms].[AddCustomer].[Name]
add1 = [Forms].[AddCustomer].[Address1]
add2 = [Forms].[AddCustomer].[Address2]


Set dbs = OpenDatabase("v:\lab\sdawOrderID\sdaw.mdb")

DoCmd.RunSQL "INSERT INTO Customer(Name, BillAddressAddr1, BillAddressAddr2) VALUES('" & Name"','" & add1 & "','" & add2 & "');"


dbs.Execute strSQL, dbFailOnError


dbs.Close
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:01
Joined
Feb 19, 2002
Messages
43,266
Are you trying to insert data into a table in a different database? Your syntax is incorrect. You are confusing DAO with the RunSQL method. there is no SQL string defined for the .execute method to execute.

REmove the .execute method and try adding the "IN" operator to the RunSQL query string.

BTW:
Dim a,b,c as string ONLY dims c as a string. a and b are dim'd as variants.
 

Users who are viewing this thread

Top Bottom