Results 1 to 9 of 9
  1. #1
    Soupy8728 is offline Novice
    Windows 11 Access 2016
    Join Date
    Mar 2024
    Posts
    13

    Need help with null values on form

    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.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,979
    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

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Soupy8728 View Post
    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.
    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

  4. #4
    Soupy8728 is offline Novice
    Windows 11 Access 2016
    Join Date
    Mar 2024
    Posts
    13
    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.

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Soupy8728 View Post
    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
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    Soupy8728 is offline Novice
    Windows 11 Access 2016
    Join Date
    Mar 2024
    Posts
    13
    Quote Originally Posted by Bob Fitz View Post
    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
    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).

  7. #7
    Soupy8728 is offline Novice
    Windows 11 Access 2016
    Join Date
    Mar 2024
    Posts
    13
    Quote Originally Posted by Bob Fitz View Post
    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
    Thanks again Bob, I'm at work now and our network restricts downloading certain files. I'll check it out when I get home. Thank you again.

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Soupy8728 View Post
    Thanks again Bob, I'm at work now and our network restricts downloading certain files. I'll check it out when I get home. Thank you again.
    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

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,979
    Quote Originally Posted by Soupy8728 View Post
    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.
    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

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form/Query handling NULL values
    By MLo in forum Forms
    Replies: 4
    Last Post: 06-21-2020, 08:23 PM
  2. Replies: 2
    Last Post: 10-07-2019, 10:46 AM
  3. Replies: 2
    Last Post: 11-19-2012, 05:42 PM
  4. Query on a Unbound form with Null Values
    By Kenny in forum Queries
    Replies: 2
    Last Post: 05-24-2012, 12:51 AM
  5. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums