Referring to buttons on subforms

johnnixon

Registered User.
Local time
Today, 14:55
Joined
Jul 27, 2006
Messages
17
(Using Access97) I have numerous forms and subforms all with the same cluster of button controls. To save repetition, have created a module where the main routines for each button is taken care of. For example, to call the routine by clicking the delete button on the ManuscriptTitleForm, the delete button event handler does:-
Private Sub BtnDelete_Click()
DeleteBtn ("ManuscriptTitleForm")
End Sub

One bit of the module code does:-
Sub DeleteBtn(FormName As String)
Forms(FormName).BtnOK.SetFocus

Unfortunately, I can't find any syntax that works to send the name of a subform or subsubform to the routine. Any advice much appreciated.

Regards

John
 
The syntax for referring to a control on a subform is:

Code:
Forms!frmMyMainFormName.sfrmMySubFormName.Form.MyControlName

So, remember that "sfrmMySubFormName" is the name of the Control that contains the subform, which can be the same name as your subform, but isn't necessarily so.
 
Bob
Thanks a lot for the helpful reply. Unfortunately, I must be too stupid. I've tried all the combinations I can think of in the call to the sub, starting with:-
EditBtn("ManuscriptTitleForm.JobLinkSubForm.Form") ,then with and without the starting exclamation mark, with and without the closing period. Each time I get the error msg "Microsoft Access can't find the form 'ManuscriptT...etc. I typed in the command using your format in a line of code directly (i.e. not as a string variable with the call to subroutine) and it works just fine. But I just can't see how to phrase it in the (" ") when calling the sub. The first "Forms" is already waiting in the sub, and I get an instant error if I try to leave it out. Sorry to be a pain, but any light you can shine into my dark tunnel?

Kind regards

John
 
Last edited:
Why doesn't mine work?

:confused: I've tried to follow the conventions listed as closely as possible (I'm using Access 2003 at work - although it's hit and miss whether I can get it working on my Access 2000 PC at home either). Can any one please tell me what I've done wrong?

DoCmd.Close acForm, "Main Menu"
DoCmd.OpenForm "GID/PO Maintenance"
[Forms]![GID/PO Maintenance]![Display GID/PO].[btnAssign].Visible = False

"Display GID/PO" is a subform on "GID/PO Maintenance".

The error message I get is "Run-time error '2465' .... can't find the field referred to"

I know I've had this working in the past - but I've been doing this for about eight hours straight now and I'm bound to have overlooked the obvious! :o
 
You're close, but not quite there:
Use:
Code:
[Forms]![GID/PO Maintenance].[Display GID/PO].Form.[btnAssign].Visible = False
 
I was so hopeful...

that this would work - but now I'm getting:

"Microsoft Office Access can't find the field '|' referred to in your expression

I wasn't even aware there was a '|' field! :(

Any suggestions where I might find this mysterious field and make it go away? I've not come across this one before and I'm flummoxed :confused:

And I've just done a quick search of these forums and the only post I found with a similar problem was referring to dates - there are no dates on either form or in the query or table that the forms refer to. I'm getting very lost.
 
Last edited:
Well, you might be having trouble because of having a forward slash in your control names. You should never use reserved words or mathematical operators in any object names. When it sees the slashes, it thinks it's either a web reference ("/") or a file reference ("\").

I would try renaming your controls and your form and see how it works. Also, if you don't put spaces in the names of forms, fields, controls, etc. it simplifies things as you don't need brackets then. Just name stuff either with an underscore (_) as a separator (example: txtMy_Text_Box_Name) or just using capital letters at the beginning of words (example: txtMyTextBoxName).
 
Thanks for the advice - I don't actually have slashes in the code, but I'll see if I can change it so that I don't have the underscore either and see if that works

:)
 

Users who are viewing this thread

Back
Top Bottom