Results 1 to 4 of 4
  1. #1
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172

    Help With Form Rules and VBA

    Hi,

    I have a form with a number of fields on it. When the form is first created, a few of these fields are 'required' in the table definition. However, users will come back later & add further information into the form. I need to set a lot of rules around the fields to force the users to enter all required information. e.g. they can't enter 'offer 2' information until all 'offer 1' information has been entered.

    With some help from this forum last week, I got it working by setting visible to False on the Form_Current procedure. However, the issue I had is that if a user entered data, went away and came back to the form, the fields they had filled out are not visible.

    I am new to VBA and have been trying to enter the following code:

    Private Sub Form_Current()
    If Field_1 Is Null Then


    Field_1.Visible = False
    Else: Field_1.Visible = True
    If Field_2 Is Null Then
    Field_2.Visible = False
    Else: Field_2.Visible = True
    End If
    End Sub

    But it's not working. Any help would be really appreciated!

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Kirsti View Post
    Hi,

    I have a form with a number of fields on it. When the form is first created, a few of these fields are 'required' in the table definition. However, users will come back later & add further information into the form. I need to set a lot of rules around the fields to force the users to enter all required information. e.g. they can't enter 'offer 2' information until all 'offer 1' information has been entered.

    With some help from this forum last week, I got it working by setting visible to False on the Form_Current procedure. However, the issue I had is that if a user entered data, went away and came back to the form, the fields they had filled out are not visible.

    I am new to VBA and have been trying to enter the following code:

    Private Sub Form_Current()
    If Field_1 Is Null Then
    Field_1.Visible = False
    Else: Field_1.Visible = True
    If Field_2 Is Null Then
    Field_2.Visible = False
    Else: Field_2.Visible = True
    End If
    End Sub

    But it's not working. Any help would be really appreciated!
    Just to get terminology straight, forms have controls, controls are bound to fields. If you use the wizard to create a form with controls, Access names the control with the same name of the bound field. I would suggest renaming the controls slightly to differentiate the control names from the field names.


    There were several problems with your code. Try this:

    Code:
    Private Sub Form_Current()
       If IsNull(Me.Field_1) Then
          Me.Field_1.Visible = False
       Else
          Me.Field_1.Visible = True
       End If
       
       If IsNull(Me.Field_2) Then
          Me.Field_2.Visible = False
       Else
          Me.Field_2.Visible = True
       End If
       
    End Sub

  3. #3
    Kirsti is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    172
    Thanks Steve, it is now working perfectly.

    And thanks for the tips on terminology - I am still getting my head around this stuff!

    Kirsti.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Wonderful...

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

Similar Threads

  1. Rules and Requirements in a Form
    By Kirsti in forum Forms
    Replies: 9
    Last Post: 02-01-2012, 06:37 PM
  2. Report rules
    By paawian in forum Reports
    Replies: 1
    Last Post: 12-29-2011, 12:14 PM
  3. Field Rules
    By darrellx in forum Database Design
    Replies: 5
    Last Post: 08-21-2011, 07:31 AM
  4. Multiple Validation Rules in a form
    By GothardTech in forum Forms
    Replies: 1
    Last Post: 04-15-2011, 01:21 PM
  5. Validation Rules
    By esglover in forum Database Design
    Replies: 1
    Last Post: 07-23-2010, 08:02 PM

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