• Help with VB code

    Author
    Topic
    #355700

    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.

    shy

    Viewing 1 reply thread
    Author
    Replies
    • #525130

      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.

      • #525242

        cheers 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. smile

    • #525129

      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.

    Viewing 1 reply thread
    Reply To: Help with VB code

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: