Results 1 to 12 of 12
  1. #1
    Join Date
    Jan 2007
    Posts
    47

    Unanswered: how to hide fields?

    Hi,

    I am pretty new to VBA. Can anyone let me know the function or procedure how to hide fields based on the fields.

    Below are the fileds in my database,

    state
    name(last, first)
    license#
    inspected

    If the name field is entered then 'inspected' field should be visible otherwise it should be invisible.

    I appreciate all your help.

    Thanks,

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    In the after update event of the name field:

    Code:
    If Len(NameField) > 0 Then
      Me.Inspected.Visible = True
    Else
      Me.Inspected.Visible = False
    End If
    Paul

  3. #3
    Join Date
    Jan 2007
    Posts
    47
    I tried to test the code but it doesn't work.

    Here is what I have in my procedure,

    Private Sub super_inspected_Enter()
    If Len(super_last_name) > 0 Then
    super_inspected.Visible = True
    Else
    super_inspected.Visible = False
    End If
    End Sub

    When I tried to enter the name field the inspected field doesn't showup.

    I appreciate all your help.

    Thanks,

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Code:
    Private Sub super_inspected_Enter()
    If Len(super_last_name) > 0 Then
    super_inspected.Visible = True
    Else
    super_inspected.Visible = False
    End If
    End Sub
    You can't have code in an event of the super_inspected control to decide if the super_inspected control is visible! The code determining if the super_inspected field is visible has to be, as pbaldy said, in the after_update event of your name control! Something like:

    Code:
    Private super_last_name_AfterUpdate()
    
    If Len(super_last_name) > 0 Then
    super_inspected.Visible = True
    Else
    super_inspected.Visible = False
    End If
    End Sub
    And if you're ever going to enter some data, leave the record and come back later, you also need to place the same code in Private Sub Form_Current().
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Which I already noted:

    Quote Originally Posted by pbaldy
    In the after update event of the name field:
    Paul

  6. #6
    Join Date
    Jan 2007
    Posts
    47
    Sorry for the confusion and Thank you so much.

  7. #7
    Join Date
    Jan 2007
    Posts
    47
    I don't have any Private Sub Form_current() in my code. So I create one with the above code but even then inspected field deosn't show up.

  8. #8
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Did you just type it in, or start from the form properties sheet so it was properly associated?
    Paul

  9. #9
    Join Date
    Jan 2007
    Posts
    47
    It works now. Thank you so much.

  10. #10
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    That's what I said, Paul!

    The code determining if the super_inspected field is visible has to be, as pbaldy said, in the after_update event of your name control!
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    That was directed at the OP, not you Missinglinq. Too often I've anticipated the next question and answered it, only to have it ignored/missed, as happened here.
    Paul

  12. #12
    Join Date
    Jan 2007
    Posts
    47
    Hey,

    I have one more question.

    I need to carry all the below fields to another form.

    state
    name(last, first)
    license#
    inspected

    I have list of prepop fileds so I have added al these fields to that list. Everything gets populated but the inspected field. As I made the inspected field visible only when the name field is filled. When I carry over the fields to other form the name is already filled and so 'inspected field is not populated. How do I load this field in the new form.

    I have a procdure for form_load so I have called super_last_name_AfterUpdate() to that form loader but it doesn't work.

    I appreciate your suggestions.

    Thanks,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •