Carrying string variables on call to sub

johnnixon

Registered User.
Local time
Today, 08:48
Joined
Jul 27, 2006
Messages
17
(Using Access97)
I want to call this standard module sub from various form modules:-
Code:
Sub NewBtn(FormName As String)
    Forms(FormName).BtnOK.Enabled = True
When I call it from a main form, this works fine:-
Code:
Private Sub BtnNew_Click()
    NewBtn ("MyForm")
This effectively makes the second line of the standard module:-
Code:
Forms!MyForm.BtnOK.Enabled = True
When I call from a subform, I need the line to effectively give me:-
Code:
Forms!MyForm.MySubForm.Form.BtnOK.Enabled = True
I can't find any combination that I can type into the NewBtn("?????") brackets on the subform module which doesn't give me the error msg "can't find the form 'MyForm....etc'".
You will make an old man very happy if you can enlighten me.
Appreciate any replies.

John
 
Last edited:
heres something that it hink would help, since it is a sub form, it is still a form, and therefor can still be called by the form name, so if the sub form name is MySubForm, then you can just use the MySubForm as the string and it would work fine, would it not?
 
Thanks Elbweb
Appreciate the reply. Unfortunately, have tried that one, and Access doesn't agree with either of us! It just says it cannot find the subform, even though the form and its subform are open together. But I am grateful, as it had gone so quiet, it looked as if no-one was out there. I may have to find some other way of doing things a lot less elegantly, with my limited knowledge.

Thanks again

Kind regards

John
 
Last edited:
another thought, have you ever put any code within the sub form? it might need to be registered so that you can call it within code...

i dont think thats the right way of saying it but, a simple way to check is within the VBA screen, do you see it on the left, the subform i mean, if you dont, just within access, goto that form, right click something, build event, and add code,and then it will be registered...

beyond that... i would say you should just maybe pass two variables? or set global variables as a form, and the form load, and them be assign as 'me' or.. i dont know, im just trying to throw some ideas out there..
 
Thanks for your futher comments, Elbweb

Sorry for the delay in replying - had visitors and couldn't sneak away to the computer haven.
Yes, there is also code in the subform module, which is where the standard module gets called from, but I get your drift. Unfortunately, as I have to do this one in Access97, I don't get a VB screen - just the code window. In, fact, pathetic as it may seem, I can't find a way in 97 to bring up the VB application screen, but I feel sure that it's registered (the subform code module, that is). Sad thing is, when I type the literal string in full on the standard module, it rushes off to the subform and does what I asked it to. It's only when it has to do it from a passed variable that it falls over. And hovering over the string variable in the code window (having put a breakpoint in), it reads what I would have thought was exactly correct. Have experimented with inserted plings and periods, and yes, tried passing two variables, as you suggested, one for the main form and one for the subform. It builds them together in the module to create the same string, but then still can't find the subform. Am almost tempted to think it might be a bug in Access, but it should heve been encountered many times by now, as the main reason, I should have thought, for having a standard module is that it can be called from many different places, and respond using passed variables.
Your last comment (global variables as a form, and the form load, and them be assign as 'me' ), I am still wresting with, and will let you know how they score when I've got my head around them.
Anyway, Elbweb, thanks a lot for your erudite suggestions and efforts, and phrasing them in such a way that even I could understand them.

Kind regards

John
 
Bob

Many thanks for that. I wish I'd seen it a few weeks ago when I was first trying to dig into Access VB. Problem now, however, is not how to address a remote control with a literal string (which the link page covers beautifully), but how to pass the form-specific info at the time of calling the module sub-routine, so that the sub routine can create the string to operate on controls on that form. I've tried so many combinations, including the obvious one of "MyForm.MySubForm.Form" in the call, but Access always says that it can't find the (sub)form. Before replying I just thought I'd try it in Access2003, in case it's a bug in '97, but that doesn't even work for a main form, using this format. This time, however, I have to make it work in '97, or give up and create the same blocks of code in every form and subform module (it's getting imminent). Thanks again for your offering. If you know how to pass the variable in '97. I'll be delighted.

Kind regards

John
 

Users who are viewing this thread

Back
Top Bottom