Could someone help me pinpoint where I'm going wrong with the following, please ?
I'm attempting to insert a record into a Table named tblTasks, using the VBA code below.
However, it's not working. I get the following message, and when I click on 'Yes', no record is inserted.
If instead I use the following code, it DOES work.
As I want to be able to expand on this and introduce other 'Task titles', I'd really like to be able to use strTaskInsertionSQL.
Why is the first block of code not picking up the value for strTaskTitle ? Perhaps an issue with the cancatenation of strTaskInsertionSQL ?
Thanks in advance for any pointers.
I'm attempting to insert a record into a Table named tblTasks, using the VBA code below.
Code:
Dim strTaskInsertionSQL As String
Dim strTaskTitle As String
strTaskInsertionSQL = "INSERT INTO tblTasks (TaskTitle, TaskCurrent, Status) VALUES ('" & strTaskTitle & "', 'Yes', 'A');"
strTaskTitle = "Task 1"
DoCmd.RunSQL strTaskInsertionSQL
However, it's not working. I get the following message, and when I click on 'Yes', no record is inserted.
If instead I use the following code, it DOES work.
Code:
Dim strTaskInsertionSQL As String
Dim strTaskTitle As String
strTaskInsertionSQL = "INSERT INTO tblTasks (TaskTitle, TaskCurrent, Status) VALUES ('" & strTaskTitle & "', 'Yes', 'A');"
strTaskTitle = "Task 1"
DoCmd.RunSQL "INSERT INTO tblTasks (TaskTitle, TaskCurrent, Status) VALUES ('" & strTaskTitle & "', 'Yes', 'A');"
As I want to be able to expand on this and introduce other 'Task titles', I'd really like to be able to use strTaskInsertionSQL.
Why is the first block of code not picking up the value for strTaskTitle ? Perhaps an issue with the cancatenation of strTaskInsertionSQL ?
Thanks in advance for any pointers.