Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005

    Question Unanswered: Testing a subform condition!

    Hello again everyone!
    I currently have a project where a form with a subform opens during a process, asking the user to select a key to assign (form - "CheckOutPinLock", subform "PinlockKeySelect subform1") to a truck driver. There is a button on the main form that will take the information from the subform and thru various update querys and macros, update that set of keys as being assigned to that driver. That part works great. One of my users pointed out though, that they can click the button without selecting any of the available keys (subform shows available key numbers, and a checkbox named "Check" that they click to select the set they want to assign) and it will continue to print documents without a key being selected. I went into the VB code on the Assign button to add a If/Then statement that if "Select" was not checked, to pop up a message box informing the user that to proceed with assignment, a key set must be selected. However, I can't find the right way to test the subform field "Select" in VB that the If/Then statement likes. The button is on the main form, the field it needs to test is on the subform. This is the first time I have needed to do this, any suggestions from all you wonderful folks who have given me such great advice in the past? Any and all help appreciated.


  2. #2
    Join Date
    Dec 2004
    Madison, WI
    If you're code is continuing, don't forget to put in your: 'Exit Sub' code so it exits the procedure correctly when you want it to.

    To test a field on a subform, use syntax like this:

    If Forms!MyMainFormName!MySubFormName!MyFieldName = "SomeValue" then
    If isnull(Forms!MyMainFormName!MySubFormName!MyFieldN ame) then...

    If there's multiple things to check, I usually design a Function and have it return a true or false based on all the conditions.


    Function retAllFieldsChecked() as boolean
    retAllFieldsChecked = false
    if Forms!MyFormName!MyFieldName1 = true then retAllFieldsChecked = true
    if Forms!MyFormName!MyFieldName2 = true then retAllFieldsChecked = true
    if Forms!MyFormName!MyFieldName3 = true then retAllFieldsChecked = true
    end function
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Dec 2005
    Yep, I was close, but not quite close enough.

    Thanks for the visual, it is working without a hitch now.

    (so close, and yet so far.......)

Posting Permissions

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