INSERT SQL works only with hard coded values

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


INSERT SQL works only with hard coded values



Cannot insert a variable using INSERT in MS ACCESS.



the insert works great when I insert a hard-coded value such as


dbs.Execute "INSERT INTO Flights " _
& "(FlightID) VALUES " _
& "('2');"



But fails with a variable


Private Sub MainSaveBtn_Click()
Dim dbs As Database
Set dbs = CurrentDb
Dim id As Integer

id = 20
Debug.Print id
dbs.Execute "INSERT INTO Flights " _
& "(FlightID) VALUES " _
& "('id');"
dbs.Close

End Sub



*Flights table has only one Integer colum named FlightID



What am i missing here?





You are trying to insert the text 'id' into an integer column.
– pritaeas
18 mins ago





Are Flight and ID fields in a table or variables in your code?
– ashleedawg
18 mins ago


Flight


ID





id is an integer variable im trying to insert its value in the table
– VLados
8 mins ago




2 Answers
2



It look like you are trying to insert "id" in the database. Try to concat your id in the String with the "+" symbol. Or just use a prepared statement to inject your variables in



The 'id' should be a integer variable and not the string 'id'. The correct SQL statement is listed below.


dbs.Execute "INSERT INTO Flights " _
& "(FlightID) VALUES " _
& "(" & CStr(id) & ");"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

QY,6sTn S9 HWK5IHrm1CY vyw
cvUoZJmDC3v vn1j g,Q2zPKKwRknyD,8vLhXcX0CCHKm,QqW5Z3Z8U8v0ViEk3D5PzH2j xucb,ByJ6z7T0hmVe,9

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham