Results 1 to 7 of 7
  1. #1
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55

    Input Form that changes depending on whats selected


    Hello,

    Im quite new to access so i have a question about building a input form.

    here is a little info about my data base first. I have test equipment that has calibration dates and we send the items off to be certified when the dates expire. The test equipment is tracked by a unique serial number.

    When the test equipment returns from being certified it comes back serviceable or un-serviceable. On my form for returning test equipment I want the Serial number to be entered. then two radio buttons under that will be serviceable or un-serviceable. Now depending on what one they click, i want certain text boxes to appear. Serviceable should have "New Expiration Date" and "Entered By" fields show up as these are the mandatory fields that need to be filled out for a serviceable item. Un-serviceable should have "Entered By" and "Fault" as these are the mandatory field required for Un-serviceable items.

    *EDIT* If i get the above to work my "New Expiration Date" and "Entered By" Fields are set as manditory fields. If they check un-serviceable will the "New Expiration Date" still be manditory in the background?

    Any help would be great.

    If anymore info is required please ask and ill do my best to try and provide more

    Thanks

    Munroe
    Last edited by MunroeM; 11-25-2015 at 08:31 AM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    youd need a bit of code to unhide these fields.
    all these boxes will exist but visible=false
    then depending on what the user clicks, unhide them:
    Code:
    sub chkServiceable_afterupdate
    
    txtEnteredBy = Environ("Username")     'auto enter regardless
    
    if chkServiceable.value then
       txtNewDate.visible = true
       txtFault.visible = false
    else
       txtNewDate.visible = false
       txtFault.visible = true
    end if
    end sub

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you need a bit of vba code behind the afterupdate event of your radio button group. each radio button defaults to a number (which you can change when creating the control) which for the sake of argument will say are 1 and 2

    you can do this in a number of ways

    1. heavy on the code
    Code:
    if radiobuttongroup=1 then
        ctrl1.visible=true
        ctrl2.visible=false
    else
        ctrl1.visible=false
        ctrl2.visible=true
    end if
    2. light on the code
    Code:
        ctrl1.visible=radiobuttongroup=1
        ctrl2.visible=radiobuttongroup<>1
    3. the above two methods mean changes to the code if you add another control, this next method requires no changes to the code, just populate the tag property of each control you want to set the visibility - 1 for radio option 1, 2 for radio option 2, leave blank for all other controls

    Code:
    dim ctrl as control
    for each ctrl in me.controls
       ctrl.visible=ctrl.tag=radiobuttongroup or ctrl.tag=""
    next ctrl

  4. #4
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55
    If i get the above to work my "New Expiration Date" and "Entered By" Fields are set as manditory fields. If they check un-serviceable will the "New Expiration Date" still be manditory in the background?

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    yes - you will need to remove this condition form the table and implement with code in your form i.e.

    in the before update of the form some code like

    Code:
    if radiobutton=1 and isnull([New Expiration Date]) then
        msgbox "You need to complete New Expiration Date"
        cancel =true
    end if

  6. #6
    MunroeM is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    55
    I have this code added now.

    Code:
    Private Sub SaveExit_Click()
         Me.SentToCal = "No"
         If ServUS = 0 And IsNull([NewDate]) Then
            MsgBox "Please Enter A Valid Expiration Date."
            Cancel = True
        End If
        If ServUS = -1 And IsNull([UpdateBy]) Then
            MsgBox "Please Enter Your Name."
            Cancel = True
        End If
        DoCmd.Close
    End Sub
    I went with toggle buttons instead of radio buttons. I will get the message box to pop up with the correct warning but when i click ok it closes my form.

    *SOLVED*How can i get it to not exit the form if there is an error ? *SOLVED*

    I added "exit sub" in my If statements






    Quote Originally Posted by Ajax View Post
    yes - you will need to remove this condition form the table and implement with code in your form i.e.

    in the before update of the form some code like

    Code:
    if radiobutton=1 and isnull([New Expiration Date]) then
        msgbox "You need to complete New Expiration Date"
        cancel =true
    end if
    Last edited by MunroeM; 11-26-2015 at 09:08 AM. Reason: Solved

  7. #7
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    modify your code to

    Code:
    Private Sub SaveExit_Click()
         Me.SentToCal = "No"
         If ServUS = 0 And IsNull([NewDate]) Then
            MsgBox "Please Enter A Valid Expiration Date."
            Cancel = True
        ElseIf ServUS = -1 And IsNull([UpdateBy]) Then
            MsgBox "Please Enter Your Name."
            Cancel = True
        else
            DoCmd.Close
        End If
        
    End Sub

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

Similar Threads

  1. Replies: 6
    Last Post: 10-27-2014, 08:05 PM
  2. Whats wrong with my query
    By Kirtap in forum Queries
    Replies: 5
    Last Post: 10-01-2013, 10:31 AM
  3. Display table data depending on selected data
    By swavemeisterg in forum Forms
    Replies: 7
    Last Post: 07-30-2013, 03:43 PM
  4. Need different amounts of data depending on a user input?
    By parkerjallen in forum Database Design
    Replies: 2
    Last Post: 11-13-2012, 03:17 PM
  5. Whats wrong with this code?
    By shabbaranks in forum Programming
    Replies: 2
    Last Post: 03-20-2012, 08:01 AM

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