INSERT Statement Help :)

Ryan142

Member
Local time
Today, 22:53
Joined
May 12, 2020
Messages
52
Hi Guys,

I've been looking for a bit on information about INSERT statements and I really haven't found much. So I find myself here again!

All I want to do is a basic INSERT Statement where the user will input data into text boxes, then when the save button is clicked, the code will insert this into the table

Here's the code I have - but it's complaining about too few parameters which maybe might be to do with how I've inserted the text boxes into the statement I don't know

Code:
Private Sub btnSave_Click()

    SQLReg = "INSERT INTO tblAircraftDetails (Registration, Model, SeatsAvailable, Remarks) " & _
             "  VALUES(txtRegistration, txtModel, txtSeats, txtRemarks)"
    CurrentDb.Execute (SQLReg)

End Sub

As always, any help is always appreciated! Thanks,
Ryan
 
Why not just use a form with controls bound the fields of the table. So much easier than using unbound forms.
 
Hi Ryan. The way I see it, this really has nothing to do with INSERT statements but more about properly creating a String in VBA.
 
The way I see it, this really has nothing to do with INSERT statements but more about properly creating a String in VBA.
I pretty much agree with that. I don't see the point of all that code when you can concatenate, such as
"INSERT INTO Table1(thedate, test, ThreeDecimal) VALUES (#" & frm.Created & "#, '" & frm.Text5 & "', " & frm.Text7 & ")"
(where text5 is text, text7 is a number)
Of course, in that example you have to declare and Set a form object. I just copied that from a test in a standard module, otherwise I would have just used Me.

Uncle, not saying your way isn't good - I'm just saying it's a lot more code instead of learning how to concatenate. There will be times when concatenation will be absolutely necessary, and that code won't fit the bill because it's not meant for say, concatenating an expression or non-sql related task. Plus all that code seems it will work for a particular sql statement, but for an additional situation that requires more or less fields, it needs to be copied and modified. That just adds unnecessary code to the code project IMHO. Besides, I don't see the Insert statement as what might be notorious as much as the task of concatenation.
 
I had to come back in to see how old this was, given that you were addressing my post. A year, almost? Thou dost procrastinate too much!
Anyway, I'm unwatching this one.
 

Users who are viewing this thread

Back
Top Bottom