'ms-access string in SQL vba
after trying '" text "' or (" text ") and some other combination after reading similar issue on RunSQL without success, hence i have to seek the more opinion here:
using Design Query and able to provide the correct SQL statement below:
INSERT INTO db_Doc_Child_SX ( Child_Doc_DD, Parent_Doc, Child_Doc, Doc_Detail_Rec )
SELECT Date() AS Expr1, db_Doc_D_bl.Doc_Rec, [Doc_Rec] & "-" & DatePart("d",Date()) AS Expr2, db_Doc_D_bl.Doc_Detail_Rec
FROM db_Doc_D_bl
WHERE (((db_Doc_D_bl.Doc_Detail_Rec)=[Forms]![Fm_Doc_Child_SX]![db_Doc_D_bl subform].[Form]![Doc_Detail_Rec]) AND ((db_Doc_D_bl.SX_Sent)=True));
the error code is - Compile Error: Expected: end of statement and highlight the d between the "".
In the Past encountering such issue, i always think of other alternative to overcome it without actually facing this issue and now i think i wish to learn properly and face this string / text with "" in the SQL statement under vba and hope senior who has the deep experience can share the proper syntax for this SQL statement.
many thanks and regards.
edit: Mr. @deluxeinformation got the right syntax and got the SQL statement to pass it without error! so the right syntax is
INSERT INTO db_Doc_Child_SX ( Child_Doc_DD, Parent_Doc, Child_Doc, Doc_Detail_Rec )
SELECT Date() AS Expr1, db_Doc_D_bl.Doc_Rec, [Doc_Rec] & '-' & DatePart('d',Date()) AS Expr2, db_Doc_D_bl.Doc_Detail_Rec
FROM db_Doc_D_bl
WHERE (((db_Doc_D_bl.Doc_Detail_Rec)=[Forms]![Fm_Doc_Child_SX]![db_Doc_D_bl subform].[Form]![Doc_Detail_Rec]) AND ((db_Doc_D_bl.SX_Sent)=True));
Solution 1:[1]
Try with single-quotes:
[Doc_Rec] & "-" & DatePart('d',Date()) AS Expr2
or use Day:
[Doc_Rec] & "-" & CStr(Day(Date())) AS Expr2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
