Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113

    Unanswered: Quick Syntax Question

    I have an option box when it is selected the text box next to it will be visible or enabled. I am getting a runtime error, that says that the expression has no value on the first line. I have the expression in the option box in the on Focus event.

    If optEMGOther = 1 Then
    txtEMGOther.Enabled = True
    Else
    txtEMGOther.Enabled = False
    End If

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Try to do it in the OnClick event

  3. #3
    Join Date
    Nov 2003
    Posts
    1,487
    Do as hammbakka has suggested. You may want to simplify things a little as well by using this code:

    Me.txtEMGOther.Enabled = Me.optEMGOther.Value


  4. #4
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113
    Quote Originally Posted by CyberLynx
    Do as hammbakka has suggested. You may want to simplify things a little as well by using this code:

    Me.txtEMGOther.Enabled = Me.optEMGOther.Value

    There is no OnClick event for a option button?

  5. #5
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113
    When the option button is true the text box should be enabled.
    If optEMGOther.Value = 1Then
    txtEMGOther.Enabled = True
    End If

    But this expressiondoes not work either. Is the expression supposed to be on the got focus?

  6. #6
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113
    When the option button is true the text box should be enabled.
    If optEMGOther.Value = 1Then
    txtEMGOther.Enabled = True
    End If

    But this expressiondoes not work either. Is the expression supposed to be on the got focus?

  7. #7
    Join Date
    Nov 2003
    Posts
    1,487
    I'm not quite sure what type Option Button you are using, but, the one that comes shipped with MSAccess does indeed contain a OnClick event.

    Is your OptionButton contained within a Option Group?


  8. #8
    Join Date
    Aug 2004
    Location
    NY
    Posts
    113
    Quote Originally Posted by CyberLynx
    I'm not quite sure what type Option Button you are using, but, the one that comes shipped with MSAccess does indeed contain a OnClick event.

    Is your OptionButton contained within a Option Group?

    Yes, it is in an option group. Any suggestions. I want to keep my group because I have other option buttons. This one is an Other. IF the option is selected, the other box will be enabled to allow input. This may not be the best design but it is for my current situation.

  9. #9
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Please find attached a sample .MDB file that enables / disables a textbox, based on the selection of an optionButton.
    Attached Files Attached Files
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  10. #10
    Join Date
    Nov 2003
    Posts
    1,487
    I have provided here a small sample form which contains a Option Group with three Option Buttons and three TextBoxes. When the DB is started, the TextBoxes are invisible and remain so until one of the three Option Buttons is selected. Which TextBox becomes visible at at any given time will depend entirely upon which Option Button is selected.

    There are many ways to do this sort of thing. If you want to use your method, then you might want to try is this way:

    It is assume here that optEMGOther is the name of your Option Group; This code would go into the OnClick event for your Frame (option group) control.

    Code:
    If optEMGOther.Value = 1 Then
       txtEMGOther.Enabled = True
    Else
       txtEMGOther.Enabled = False
    End If
    This of course would only work with one TextBox. If you want to add more TextBoxes (lets say 3 of them) then the code may look like:

    Again, in the OnClick event of your Option Group Frame control:

    Code:
    If optEMGOther.Value = 1 Then
       txtEMGOther.Enabled = True
    Else
       txtEMGOther.Enabled = False
    End If
    
     
    If optEMGOther.Value = 2 Then
       txtEMG2ndOther.Enabled = True
    Else
       txtEMG2ndOther.Enabled = False
    End If
    
    If optEMGdOther.Value = 3 Then
       txtEMG3rdOther.Enabled = True
    Else
       txtEMG3rdOther.Enabled = False
    End If
    'and so on.....
    Hope this clears things up a little.

    Attached Files Attached Files

Posting Permissions

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