Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing variables from a form to a subform (2000)

    Hi all,

    I am trying to create a form that includes a subform. I want the ID Number and the Department Name to pass into the subform from the form. I have created a module and declared my variables in there.

    I have event procedures in the actual form that will store the information (after the user updates the text box) into the variables. And I have an event procedure written for the subform such that when one of the text boxes in the subform has the focus, then the data in the variables should update text boxes on the subform. When I go to try to actually input data into my form and
    then put the focus on the text box in my subform, it says that there is no data in my variables. How can I correct this?

    Thanks,
    Kindra

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing variables from a form to a subform (2000)

    Of course, I don't know the exact design of your form and subform. The "usual" way to do this is to set the Link Master Fields and Link Child Fields for the subform to the combination of ID Number and Department Name. This will automatically fill in these fields in the subform (do I sense a d

  3. #3
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing variables from a form to a subform (2000)

    That worked! Thanks Hans....

    And you're right, this is deja vu [img]/forums/images/smilies/smile.gif[/img] I appreciate your help!

  4. #4
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing variables from a form to a subform (2000)

    Another question related to this subject:

    I'm doing some error checking on my form -- making sure that the user has filled in the required fields and such (if they haven't, a msgbox will pop up and require the user to fill in the field before they can save). However, I'm not sure how to error check my subform as the "save" button (my event procedure is cmdSave_Click) is on my form and doesn't recognize things in my subform.

    My initial thought was to create a function in my subform that will check the subform and then call that function in my form. Will that work even though I'm not passing a variable?

    Thanks!

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing variables from a form to a subform (2000)

    Wouldn't it be better to check the subform record in the Before Update event of the subform? It's hard to check things from the main form because the subform will usually contain more than one record corresponding to the record in the main form.

  6. #6
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing variables from a form to a subform (2000)

    Okay, so I am checking the subform in the Before_Update event and that works okay. But when the user goes to press the "Save" button, if there is data missing in the subform, a msgbox will popup informing them what data is missing, and then immediately after it says "your record has been saved" because the data in the main form is complete, therefore it passes all of the requirements. How can I get that message NOT to display until all of the required data has been entered?

    Thanks,
    Kindra

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing variables from a form to a subform (2000)

    Kindra,

    You'll have to provide more detailed information about what you are doing, or post a stripped down version of the database.

  8. #8
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing variables from a form to a subform (2000)

    Here it is (FYI: the data in the form is not real data).
    Attached Files Attached Files

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing variables from a form to a subform (2000)

    In the Before Update event of the subform, you warn the user, but don't cancel the update if there are missing data. Try this:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.EFFECTIVE_DATE) = True Then
    MsgBox "Please enter an effective date"
    Me.EFFECTIVE_DATE.SetFocus
    Cancel = True
    ElseIf IsNull(Me.END_DATE) = True Then
    MsgBox "Please enter an end date"
    Me.END_DATE.SetFocus
    Cancel = True
    ElseIf IsNull(Me.frmCode) = True Then
    MsgBox "Please choose a status: student, non-student, or work study"
    Me.frmCode.SetFocus
    Cancel = True
    ElseIf Me.frmCode = "6040" And Me.txtWorkStudy = 0 Then
    MsgBox "Please enter a work study amount"
    Me.txtWorkStudy.SetFocus
    Cancel = True
    ElseIf Me.HOURLY_RATE < 1 Then
    MsgBox "Please enter an hourly rate greater than $0.00"
    Me.HOURLY_RATE.SetFocus
    Cancel = True
    ElseIf Me.HOURS_PER_WEEK < 1 Then
    MsgBox "Please enter how many hours per week employee will be working"
    Me.HOURS_PER_WEEK.SetFocus
    Cancel = True
    ElseIf Me.WEEKS_PER_YEAR < 1 Then
    MsgBox "Please enter how many weeks per year employee will be working"
    Me.WEEKS_PER_YEAR.SetFocus
    Cancel = True
    End If
    End Sub

  10. #10
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing variables from a form to a subform (2000)

    Hans,

    For some reason this works just about perfectly in the attached database, but when I go to use it in my real database, I get the following error:

    Method or Data Member not Found.

    ?????

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing variables from a form to a subform (2000)

    On which line?

  12. #12
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing variables from a form to a subform (2000)

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.EFFECTIVE_DATE) = True Then
    MsgBox "Please enter an effective date"
    Me.EFFECTIVE_DATE.SetFocus

    The Private Sub line is highlighted, and then the cursor is pointing to "SetFocus".

    Thanks,
    Kindra

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing variables from a form to a subform (2000)

    You did put the code in the Before Update event of the subform, I hope?

    In the subform in the database you attached, EFFECTIVE_DATE is both the name of the control and its control source, and this control is a text box. Does that hold in the "real" database too?

  14. #14
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing variables from a form to a subform (2000)

    No, it was txtEffectiveDate in the "real" database.

    I did put it in the BeforeUpdate subform.

    I just don't understand why it was working in the version attached here and not in my regular database. I did try to see what options access gave me if I just typed "Me.EFFECTIVE_DATE...." and it only gave me "Value" and NOT "SetFocus".

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing variables from a form to a subform (2000)

    In your real database, EFFECTIVE_DATE is the name of a field in the table behind the subform, while txtEffectiveDate is the name of the control bound to this field. The field is *not* the same as the control. SetFocus is a method of a control, not of a field. So you must use txtEffectiveDate.SetFocus.
    In the attached database, this difference was not apparent, since control and field have the same name there.

Page 1 of 2 12 LastLast

Posting Permissions

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