Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with VB code

    Can someone help me with some VB code in Access 97?
    I am currently working on a form for entering address details for companies or individuals for use in a mailing list database.
    The form includes (amongst other things) text boxes for the following fields:
    txtCompanyName
    txtIndividualFirstName
    txtIndividualLastName
    I have also incorporated on the form an option group with option buttons as follows:
    optCompany
    optIndividual
    I would like to create an event procedure for the OnClick event property of the optCompany option button so that when the optCompany option button is selected, the txtIndividualFirstName and txtIndividualLastName text boxes are not visible on the form.
    A similar event procedure for the OnClick event property of the optIndividual option button would make the txtCompanyName text box invisible on the form.
    By the way, I have made the optCompany option button the default selection in the option group.
    Any help / ideas would be greatly appreciated.

    <img src=/S/shy.gif border=0 alt=shy width=15 height=15>

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Help with VB code

    Hi,
    I would put something like the following in the BeforeUpdate event of your optiongroup's frame:
    With Me
    If !Frame1 = 1 then
    !txtCompanyName.Visible = True
    !txtIndividualFirstName.Visible = False
    !txtIndividualLastName.Visible = False
    else
    !txtCompanyName.Visible = False
    !txtIndividualFirstName.Visible = True
    !txtIndividualLastName.Visible = True
    End If
    End With
    where Frame1 is the name of the OptionGroup frame control and I have assumed that optCompany has the value 1 and optIndividual has another value.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with VB code

    I prefer to use the enabled property of controls rather than the visible property. Since the company option is the default selection set the enabled property of the individual controls to false. Then in the after update event of the option group use an if...then or select case statement to set the properties of the appropriate controls. Something like this:

    Const conCompany as Integer = 1
    Const conIndividual as Integer = 2

    Select Case optAddressType ' Name of your option group
    Case conCompany
    Me.txtIndividualFirstName.Enabled = False
    Me.txtcompanyName.Enabled = True
    Case conIndividual
    Me.txtIndividualFirstName.Enabled = True
    Me.txtcompanyName.Enabled = False
    End Select

    You will also need a similar statement in the form's current event in which case you might want to put the const statements in the form module declarations section.

  4. #4
    New Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with VB code

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Thank you Paul! Thank you Rory! I tried out both your suggestions and they work a treat. Just what I was looking for. Thanks again for taking the time to help. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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