I have a form displaying values from a number of tables.(Test Cases, Users, Method, Levels, Priority, Builds). TID is a field linking the table "Test Cases" to another table. Normally when this form is accessed TID value is automatically filled in.
If there is a record in Test Case table which is linked to this TID, it will be displayed. When the button "Add Record" is selected a new record is added by copying appropriate fields from the currently displaying record.
The command used to append a record is as follows:
DoCmd.RunSQL "Insert Into [Test Cases] (Name, AuthorID, MethodID, LevelID, PriorityID, BuildID, TestID) VALUES (" & _
TCName.Value & "," & _
IIf(Len(TCAuthor.Value) = 1, DLookup("ID", "Users"), TCAuthor.Value) & "," & _
IIf(Len(TCMethod.Value) = 1, DLookup("ID", "Method"), TCMethod.Value) & "," & _
IIf(Len(TCLevel.Value) = 1, DLookup("ID", "Levels"), TCLevel.Value) & "," & _
IIf(Len(TCPriority.Value) = 1, DLookup("ID", "Priority"), TCPriority.Value) & "," & _
IIf(Len(TCBuild.Value) = 1, DLookup("ID", "Builds"), TCBuild.Value) & "," & _
Str(TID.Value) & ");"
When I run the code I am getting a syntex error. I tried to search instructions of using SQL commands in "DoCmd.RunSQL" on the web. But, I could not find any document which clearly provides instuctions. Eg. When to use "&", double quoting, etc. Could you please help me in
- telling me the syntex error in the above line of code
- directing me to a document, site, or a book that clearly explains how to use SQL commands in "DoCmd.RunSQL".
I have already spent many hours in fixing this line of code. Please help me to get out of this problem.
VAKJay
If there is a record in Test Case table which is linked to this TID, it will be displayed. When the button "Add Record" is selected a new record is added by copying appropriate fields from the currently displaying record.
The command used to append a record is as follows:
DoCmd.RunSQL "Insert Into [Test Cases] (Name, AuthorID, MethodID, LevelID, PriorityID, BuildID, TestID) VALUES (" & _
TCName.Value & "," & _
IIf(Len(TCAuthor.Value) = 1, DLookup("ID", "Users"), TCAuthor.Value) & "," & _
IIf(Len(TCMethod.Value) = 1, DLookup("ID", "Method"), TCMethod.Value) & "," & _
IIf(Len(TCLevel.Value) = 1, DLookup("ID", "Levels"), TCLevel.Value) & "," & _
IIf(Len(TCPriority.Value) = 1, DLookup("ID", "Priority"), TCPriority.Value) & "," & _
IIf(Len(TCBuild.Value) = 1, DLookup("ID", "Builds"), TCBuild.Value) & "," & _
Str(TID.Value) & ");"
When I run the code I am getting a syntex error. I tried to search instructions of using SQL commands in "DoCmd.RunSQL" on the web. But, I could not find any document which clearly provides instuctions. Eg. When to use "&", double quoting, etc. Could you please help me in
- telling me the syntex error in the above line of code
- directing me to a document, site, or a book that clearly explains how to use SQL commands in "DoCmd.RunSQL".
I have already spent many hours in fixing this line of code. Please help me to get out of this problem.
VAKJay