Results 1 to 6 of 6
  1. #1
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75

    Check for NULL text box when clicking save on form

    Hi, is there feature whereby when i click on the save button, if there is a textbox which is empty or null the form would not save??

    I also have another question is that, is there somehow when i open the form page which i have created, normally the when we open the form it would appear the first record of the form (for example 1 of 6). So my question is that is there any setting when i open the form i would be a new record page where i can straight enter information into the form without clicking to a new page??


  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Answer to you second question go to Form Properties, Click on Data, Select Yes. Generally this option for a Form is No by default. Checking this option Yes will always open your form in a data entry mode i.e. a blank form.

    Answer to you first question. I will assume yu alreadyhave a save button on your form. Go to the command Button Properties, Select event, Then select OnClick event and open the Vb code of the button. You will find a code very similar to one below:

    Private Sub Command6_Click()
    On Error GoTo Err_Command6_Click

    If IsNull(Me.Inventory) Then
    MsgBox "The inventory field is blank", vbInformation
    DoCmd.GoToControl "Inventory"
    Else

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    End If

    Exit_Command6_Click:
    Exit Sub

    Err_Command6_Click:
    MsgBox Err.Description
    Resume Exit_Command6_Click

    End Sub

    The part of the code in red is already there. Please type the code in black.

    I have a form in which there is a field called inventory. If it is null a msgbox is displayed and the cursor moves automatically to the inventory field.


  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Another method, and one I prefer, is to place all such validation code in the BeforeUpdate event of the form. That event can be cancelled if some validation fails and fires regardless of how the form is closed.

  4. #4
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    thank for help guys....

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Yes I agree with Rural Guy on this to coz the validation code will not help you if you have a close button activate on your form. even if validation fails the user can still close the form and the data is saved in your table. More over even if you create a close Command button on your form and place the validation code in its Onclick event and de-activate the close on button on the form the user can still close the database and the unvalidated data is saved in your table. So BeforeUpdate even is much more safe.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by cwwaicw311 View Post
    thank for help guys....
    Is this thread ready for you to follow the link in my sig and mark as Solved?

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

Similar Threads

  1. Replies: 2
    Last Post: 01-29-2010, 11:33 AM
  2. Save and Go to another form - simple yes?
    By durstlaw in forum Forms
    Replies: 1
    Last Post: 12-15-2009, 12:46 AM
  3. hide text box till you un-tick check box
    By islandboy in forum Access
    Replies: 14
    Last Post: 09-06-2009, 10:08 AM
  4. Replies: 0
    Last Post: 04-13-2009, 04:02 AM
  5. Form requesting to save changes
    By stevo2820 in forum Forms
    Replies: 0
    Last Post: 07-30-2007, 07:41 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