Solved Adding a record to a table from form data (1 Viewer)

TajikBoy

Member
Local time
Today, 02:44
Joined
Mar 4, 2011
Messages
82
Hi Guys,

Trying to add a record to an existing table from the form data, which is already linked to another table and of course, failing spectacularly !!!

Below is my simple code and I am getting a syntax error in the HotelName field to start with, probably next ones will also follow ;)

Where am I going wrong?

Rich (BB code):
Dim strSQL As String

strSQL = "INSERT INTO tblFFEBudgets (HotelName, BudgetYear, Reference, Description, Justification) VALUES (" & _
               Me.HotelName & ", '" & _
               Me.RFAYear & "', " & _
               Me.BudgetRef & ", " & _
               Me.Description & ", " & _
               Me.Justification & ");"
    
DoCmd.RunSQL strSQL
 

JHB

Have been here a while
Local time
Today, 11:44
Joined
Jun 17, 2012
Messages
7,732
You need to surround text string with an apostrophe, numbers doesn't need apostrophe

VALUES ('" & _
Me.HotelName & "', '" & _
Me.RFAYear & "', " & _
 

TajikBoy

Member
Local time
Today, 02:44
Joined
Mar 4, 2011
Messages
82
Hi Guys,

Trying to add a record to an existing table from the form data, which is already linked to another table and of course, failing spectacularly !!!

Below is my simple code and I am getting a syntax error in the HotelName field to start with, probably next ones will also follow ;)

Where am I going wrong?

Rich (BB code):
Dim strSQL As String

strSQL = "INSERT INTO tblFFEBudgets (HotelName, BudgetYear, Reference, Description, Justification) VALUES (" & _
               Me.HotelName & ", '" & _
               Me.RFAYear & "', " & _
               Me.BudgetRef & ", " & _
               Me.Description & ", " & _
               Me.Justification & ");"
   
DoCmd.RunSQL strSQL
Found it..... It's bloody quotes again...I'm never gonna learn this !!!

Have a fantastic quote error free day chaps !
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:44
Joined
Sep 21, 2011
Messages
14,311
Another way I beleive, is to use a udf and just set it's parameters.
No special enclosing of charcaters needed then.

Search here as it has been mentioned several times.

Here is one such example

and in slightly a different way

 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:44
Joined
Feb 19, 2002
Messages
43,293
Any particular reason you are not using a bound form? When you use bound forms, Access does the heavy lifting. That is the whole point of using Access:)
 

Users who are viewing this thread

Top Bottom