Hi,
I am Using Access 2010/VBA. I am having problems creating inline SQL INSERT. Here's my code. The strSQL contains the sql and it doesn't like it no matter what I do:
Set db3 = CurrentDb()
Set rst3 = db3.OpenRecordset("tbl_Mass_Upload_Template_Specialist", dbOpenDynaset)
Do Until rst3.EOF
DoCmd.SetOrderBy "Specialist"
hold_Specialist = rst3![Specialist] 'errors here with No current record
If hold_Prev_Specialist <> hold_Specialist Then
hold_Prev_Specialist = hold_Specialist
Export_Report
End If
hold_GLN = Nz(rst3![GLN], " ")
hold_VBU = rst3![VBU]
hold_Highest_Level_GTIN = Nz(rst3![Highest_Level_GTIN], " ")
hold_Lowest_Level_GTIN = Nz(rst3![Lowest_Level_GTIN], " ")
hold_Assortment_Number = rst3![Assortment_Number]
hold_Item_Number = rst3![Item_Number]
hold_Model_Number = Nz(rst3![Model_Number], " ")
hold_Country = Nz(rst3![Country], " ")
hold_Internal = Nz(rst3![Internal], " ")
hold_Category = Nz(rst3![Category], " ")
hold_Item_Type = Nz(rst3![Item_Type], " ")
hold_Item_Description = Nz(rst3![Item_Description], " ")
hold_Customer_Description = Nz(rst3![Customer_Description], " ")
strSQL = "INSERT Into tbl_Mass_Upload_Template_Specialist_Next (Specialist, GLN, VBU, Highest_Level_GTIN, Lowest_Level_GTIN, Assortment_Number, Item_Number, Model_Number, Country, Internal, Category, Item_Type, Item_Description, Customer_Description) Values (hold_Specialist, hold_GLN, hold_VBU, hold_Highest_Level_GTIN, hold_Lowest_Level_GTIN, hold_Assortment_Number, hold_Item_Number, hold_Model_Number, hold_Country, hold_Internal, hold_Category, hold_Item_Type, hold_Item_Description, hold_Customer_Description)"
DoCmd.RunSQL strSQL
rst3.MoveNext
Loop
I've tried it 2 ways wondering if I need to put text fields in quotes, one with and one without.
With:
strSQL = "INSERT Into tbl_Mass_Upload_Template_Specialist_Next (Specialist, GLN, VBU, Highest_Level_GTIN, Lowest_Level_GTIN, Assortment_Number, Item_Number, Model_Number, Country, Internal, Category, Item_Type, Item_Description, Customer_Description) Values ('" & hold_Specialist & "', "'" & hold_GLN & "'', hold_VBU, '" & hold_Highest_Level_GTIN & "'', '" & hold_Lowest_Level_GTIN & "'', hold_Assortment_Number, hold_Item_Number, '" & hold_Model_Number & "'', '" & hold_Country & "'', '" & hold_Internal & "'', '" & hold_Category & "'', '" & hold_Item_Type & "'', '" & hold_Item_Description & "'', '" & hold_Customer_Description & "'')"
Without:
strSQL = "INSERT Into tbl_Mass_Upload_Template_Specialist_Next (Specialist, GLN, VBU, Highest_Level_GTIN, Lowest_Level_GTIN, Assortment_Number, Item_Number, Model_Number, Country, Internal, Category, Item_Type, Item_Description, Customer_Description) Values (hold_Specialist, hold_GLN, hold_VBU, hold_Highest_Level_GTIN, hold_Lowest_Level_GTIN, hold_Assortment_Number, hold_Item_Number, hold_Model_Number, hold_Country, hold_Internal, hold_Category, hold_Item_Type, hold_Item_Description, hold_Customer_Description)"
For the one without quotes it doesn't find the field/parameter.
For the one with quotes it gives me an invalid SELECT INSERT.
Appreciate any assistance!
I am Using Access 2010/VBA. I am having problems creating inline SQL INSERT. Here's my code. The strSQL contains the sql and it doesn't like it no matter what I do:
Set db3 = CurrentDb()
Set rst3 = db3.OpenRecordset("tbl_Mass_Upload_Template_Specialist", dbOpenDynaset)
Do Until rst3.EOF
DoCmd.SetOrderBy "Specialist"
hold_Specialist = rst3![Specialist] 'errors here with No current record
If hold_Prev_Specialist <> hold_Specialist Then
hold_Prev_Specialist = hold_Specialist
Export_Report
End If
hold_GLN = Nz(rst3![GLN], " ")
hold_VBU = rst3![VBU]
hold_Highest_Level_GTIN = Nz(rst3![Highest_Level_GTIN], " ")
hold_Lowest_Level_GTIN = Nz(rst3![Lowest_Level_GTIN], " ")
hold_Assortment_Number = rst3![Assortment_Number]
hold_Item_Number = rst3![Item_Number]
hold_Model_Number = Nz(rst3![Model_Number], " ")
hold_Country = Nz(rst3![Country], " ")
hold_Internal = Nz(rst3![Internal], " ")
hold_Category = Nz(rst3![Category], " ")
hold_Item_Type = Nz(rst3![Item_Type], " ")
hold_Item_Description = Nz(rst3![Item_Description], " ")
hold_Customer_Description = Nz(rst3![Customer_Description], " ")
strSQL = "INSERT Into tbl_Mass_Upload_Template_Specialist_Next (Specialist, GLN, VBU, Highest_Level_GTIN, Lowest_Level_GTIN, Assortment_Number, Item_Number, Model_Number, Country, Internal, Category, Item_Type, Item_Description, Customer_Description) Values (hold_Specialist, hold_GLN, hold_VBU, hold_Highest_Level_GTIN, hold_Lowest_Level_GTIN, hold_Assortment_Number, hold_Item_Number, hold_Model_Number, hold_Country, hold_Internal, hold_Category, hold_Item_Type, hold_Item_Description, hold_Customer_Description)"
DoCmd.RunSQL strSQL
rst3.MoveNext
Loop
I've tried it 2 ways wondering if I need to put text fields in quotes, one with and one without.
With:
strSQL = "INSERT Into tbl_Mass_Upload_Template_Specialist_Next (Specialist, GLN, VBU, Highest_Level_GTIN, Lowest_Level_GTIN, Assortment_Number, Item_Number, Model_Number, Country, Internal, Category, Item_Type, Item_Description, Customer_Description) Values ('" & hold_Specialist & "', "'" & hold_GLN & "'', hold_VBU, '" & hold_Highest_Level_GTIN & "'', '" & hold_Lowest_Level_GTIN & "'', hold_Assortment_Number, hold_Item_Number, '" & hold_Model_Number & "'', '" & hold_Country & "'', '" & hold_Internal & "'', '" & hold_Category & "'', '" & hold_Item_Type & "'', '" & hold_Item_Description & "'', '" & hold_Customer_Description & "'')"
Without:
strSQL = "INSERT Into tbl_Mass_Upload_Template_Specialist_Next (Specialist, GLN, VBU, Highest_Level_GTIN, Lowest_Level_GTIN, Assortment_Number, Item_Number, Model_Number, Country, Internal, Category, Item_Type, Item_Description, Customer_Description) Values (hold_Specialist, hold_GLN, hold_VBU, hold_Highest_Level_GTIN, hold_Lowest_Level_GTIN, hold_Assortment_Number, hold_Item_Number, hold_Model_Number, hold_Country, hold_Internal, hold_Category, hold_Item_Type, hold_Item_Description, hold_Customer_Description)"
For the one without quotes it doesn't find the field/parameter.
For the one with quotes it gives me an invalid SELECT INSERT.
Appreciate any assistance!