simple question

roh_8_it_3

Registered User.
Local time
Today, 15:55
Joined
Feb 15, 2005
Messages
79
hi all,

How can i access the controls of the subform in the mainform.I m using access 2k.

I m using this syntax [forms]![formname]!contolname.but its saying that access cant find the form referred in the code.

Thanks
 
Me.ctlMySubFormControl.Form.txtMyTextBox

Me equates to a pointer to the Form where the code is running.
Me.ctlMySubFormControl equates to a pointer to the Control that contains the Sub-Form.
Me.ctlMySubFormControl.Form equates to a pointer to the Form in that control.
Me.ctlMySubFormControl.Form.txtMyTextBox equates to a pointer in the control in that Form.

Me.ctlMySubFormControl.Form.txtMyTextBox equates to the default property of that control which is the Value of that control… if it has a Value property.

For any other property of that control, other than the default, you will need to spell it out, example: -

Me.ctlMySubFormControl.Form.txtMyTextBox.ForeColor

Returns the fore colour of a text box on the sub form.

When going down two levels then ctlMySubFormControl.Form needs to be repeated as in: -

Me.ctlMySubFormControl.Form.ctlMySubFormControl.Form.txtMyTextBox.ForeColor

Hope that helps.

Regards,
Chris.
 
Very well explained, ChrisO.
I remember having a hard time with this as a beginner.
 
Same question, other person. :)

Ok, I am in a module.

Trying to access a value I saved in a graphical component on a form I displayed modal, but then closed, (not hidden).

(this is a label)
Me.Forms("frmImportParameters").UserInput.Caption

gives me an error, Invalid use of Me keyword.

When I watch it in the debug window (without me.), it says
<Microsoft Access can't find the form 'frmImportParameters' referred to in a macro expression or Visual Basic code.@* The form you referenced may be closed or may not exist in this database.
* Microsoft Access may have encountered a compile error in a Vis
Then I believe the debug window runs out of space.

Please help. :confused:

-Canderel
 
Forms("frmImportParameters").UserInput.Caption
 
Canderel,

Me refers to a Class. Each form and report has its own Class module to which you can use this keyword. It has nothing to do with the Forms collection.
 
This is what happens:


Me.Forms("frmImportParameters").UserInput.Caption


gives error

"Invalid use of Me keyword"


without the Me.

Forms("frmImportParameters").UserInput.Caption


gives error (in debug watch window)

Microsoft Access can't find the form 'frmImportParameters' referred to in a macro expression or Visual Basic code.@* The form you referenced may be closed or may not exist in this database.
* Microsoft Access may have encountered a compile error in a Vis


So what I want to know is how do I access this via my module?

Here is my code that somehow doesn't work. (Well, it runs, but it goes to the error handler always... and it could be because of the OnError goto ErrorHandler)

PHP:
    If Not Forms("frmImportParameters").UserInput.Caption = "Y" Then
        GoTo ErrorHandler
    End If
 
Last edited:
The form is closed and is therefore not loaded into memory. You can't refer to something that isn't there.

Rather than close the form, you might consider hiding it. Or you can store the Caption you want to a variable, close the form, and then refer to this variable.
 
Cool... Thanks, so I'll hide it in my form, and then close it after I referenced that part.

I thought it might be that. But I had a problem when I didn't close it, the 'modal'-ness of the form got lost when I redisplayed it from a hidden location.

Thank you so much for your time.
 
well i m beginner in access.Thanks for all the replies but sorry its not solving my problem.

I have main form with the save button and also the sub form with the save buton.so i have applied the mandatory checks for the controls of the subform on the click of the sub form save button.

But the user can fill the some information in the subform and if he clicks on the save button on the mainform the incomplete records get saved in the database which i dont want.

so on the save button of the main form i also have to apply these checks but i am unable to refer to the controls of the subform in the mainform.

I tried to use these syntaxes but havent got it fixed.

Any help on this pls.
 
Well without any of your code to work with you should be able to call the sub form save event before doing the checks in the main form.

Code behind main form: -

Code:
Option Explicit
Option Compare Text


Private Sub cmdMainFormSave_Click()

    Me.ctlMySubFormControl.Form.cmdSubFormSave_Click

    MsgBox "Doing my checks in the Main Form."
    
End Sub

Code behind sub form: -
Code:
Option Explicit
Option Compare Text


Public Sub cmdSubFormSave_Click()

    MsgBox "Doing my checks in the Sub Form."

End Sub
Please note the word Public.

Hope that helps.

Regards,
Chris.
 
Thanks ..that works i have tested it.

but i have a question.On the save button of the subform i m exiting the save sub if the checks are not satisfied.

when i call the subform save sub from the main form save sub.It displays me the message but then docmd.saverecord gets executed.

well i also like to exit the the main form's save sub.i mean how can i pass this information to the main form to exit the sub.

thanks
 
How about something like this: -

In the Main Form.

Code:
Option Explicit
Option Compare Text


Private Sub cmdMainFormSave_Click()
    Dim AllChecksAreOK As Boolean

    If (Me.ctlMySubFormControl.Form.DoSubFormChecks()) Then
        ' If all the checks in the Main Form are correct Then
          '  AllChecksAreOK = True
        ' End If
    
        If (AllChecksAreOK) Then
            DoCmd.RunCommand acCmdSaveRecord
        Else
            MsgBox "Main Form Records are Incomplete."
        End If
    End If
    
End Sub

In the Sub Form.


Code:
Option Explicit
Option Compare Text


Private Sub cmdSubFormSave_Click()

    Call DoSubFormChecks
    
End Sub


[b]Public[/b] Function DoSubFormChecks() As Boolean
    Dim AllChecksAreOK As Boolean

    ' Do all your checks.

    ' If all the checks in the Sub Form are correct Then
         AllChecksAreOK = True
    ' End If

    If (AllChecksAreOK) Then
        DoCmd.RunCommand acCmdSaveRecord
        DoSubFormChecks = True
    Else
        MsgBox "Sub Form Records are Incomplete."
        DoSubFormChecks = False
    End If

End Function
If you can’t get that to work can you post a small demo in A97 please.

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom