Hello all,
I have copied some VBA from a youtube video and it does what I need it to do except I don't want the "Insert" button to do anything if the form fields are blank. Can someone please explain what I need to edit? Thank you.
Hello all,
I have copied some VBA from a youtube video and it does what I need it to do except I don't want the "Insert" button to do anything if the form fields are blank. Can someone please explain what I need to edit? Thank you.
Why not just show the code?, within code tags
Why do I have to download a DB and go searching for whatever code you are talking about?
Help us to help you. If you cannot be bothered to put any effort in, why do you think others should on your behalf?
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Perhapd something like:
Code:Private Sub Command12_Click() If Nz(ftxt, 0) > 0 And Nz(ltxt, 0) > 0 And Nz(sportcomb, 0) > 0 And Nz(agetxt, 0) > 0 Then CurrentDb.Execute "Insert into table1(firstname,lastname,sport,age) values" & "('" & ftxt & "', '" & ltxt & "', '" & sportcomb & "', " & agetxt & ")" Else MsgBox "More Data Required" End If subform1.Requery End Sub
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
I’m new to all of this so I was just attaching my file for review. Not sure how to do what you are requesting. Thank you anyways.
I'm guessing that this is a response to post #2.
See attached db in which I have altered your code as I had suggested in post #3
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
Thanks Bob. This seems to work except the nz(agetxt, 0) >0 .....this field can actually be zero (I just used Age as the the example and it will be changed to another title once I get everything working).Perhapd something like:
Code:Private Sub Command12_Click() If Nz(ftxt, 0) > 0 And Nz(ltxt, 0) > 0 And Nz(sportcomb, 0) > 0 And Nz(agetxt, 0) > 0 Then CurrentDb.Execute "Insert into table1(firstname,lastname,sport,age) values" & "('" & ftxt & "', '" & ltxt & "', '" & sportcomb & "', " & agetxt & ")" Else MsgBox "More Data Required" End If subform1.Requery End Sub
The example is basic. In the example given, the button will not insert a new record if any of the controls are empty.
It could be made to set the focus to the control that is blank and tell the user which control needs attention.
If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
Bob Fitzpatrick
Just like Bob has done in post #3
You copy your code, press the # button in the message toolbar and paste the code with the tags generated.
Like this
Code:Just like Bob has done in post #3 You copy your code, press the # button in the message toolbar and paste the code with the tags generated.
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba