Skip to content
Advertisement

How to insert a value from DLookup into a table

Ive created a DLookup to search for the table ([Copy of tblTypeOfAsset]) record i have just added from combo boxes to find the ID. From here i want to insert this value into another table, just to test that its working. Beneath is the code ive tried to use.

Private Sub Button_Click()

CurrentDb.Execute "INSERT INTO [Copy Of tblTypeOfAsset](Manufacturer, Model, Version, CalInterval) Values ('" & Me.CBOFirm & "','" & Me.CBOComms & "' , '" & Me.CBOSpSettings & "','" & Me.CBOConfigP & "');"

Dim varx As Variant



varx = DLookup("TypeID", "[Copy Of tblTypeOfAsset]", "[Manufacturer] = Forms![JA_Data_Input_Info]!CBOFirm And [Model] = Forms![JA_Data_Input_Info]!CBOComms And [Version] = Forms![JA_Data_Input_Info]!CBOSpSettings")

CurrentDb.Execute "INSERT INTO 1test (test) VALUES ('varx')"



End Sub

this code inserts a sting ‘varx’ and not the ID value, without the commas i get a “runtime error: ‘3061’: Too few parameters. Expected 1.”

Advertisement

Answer

Concatenate the value and the SQL:

CurrentDb.Execute "INSERT INTO 1test (test) VALUES ('" & varx & "')"
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement