r/MSAccess•
urik_heian

INSERT INTO structure

[SOLVED]

Hi, I'm beginning my journey in SQL/Visual Basic and I don't know how I should approach a new insertion in my table.

My table "t_Example", has four fields "ID, Company, Product, Year".

I have a form with three text boxes where the user should provide these information. So: "txtCompany", "txtProduct", "txtYear".

Within my SQL Form Code I have:

Private Sub CmdInsert_Click()
     Command = "INSERT INTO t_Example (Company, Product, Address) VALUES ('" & TxtCompany & "','" & TxtProduct & "'," & TxtYear & ")"
     CurrentDb.Execute (Command)
End Sub 

This code works perfectly when I open a form, fill the three text boxes and hit the button "CmdInsert".

However, sometimes I may not know the Company or the Year or the Product... So, when I open up the form, fill just whatever I have and hit "CmdInsert" I get an error pointing to INSERT INTO.

That means that if I use INSERT INTO I have to give every field I declared, right? Company, Product and Year in this example.

How can I do so that if I don't fill a text box it's considered Null (leaving a blank cell in my table)?

Posted Jul 21, 2017, 10:24 PM UTC

13
Loading comments…