Solved Adding a record to a table from form data

TajikBoy

Member
Local time
Today, 09:52
Joined
Mar 4, 2011
Messages
83
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
 
You need to surround text string with an apostrophe, numbers doesn't need apostrophe

VALUES ('" & _
Me.HotelName & "', '" & _
Me.RFAYear & "', " & _
 
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 !
 
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

 
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

Back
Top Bottom