By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Calling a function

P: n/a
I have a form with a subform. The form has a button which opens a
dialogbox. I would like the dialog box to call a sub in the subform.
I know how I would do this in C++, but I can't seem to figure it out in
visual basic.

Is this simply a matter of changing the sub to public instead of
private and then using some kind of method to execute the sub? If so,
what is that method? If not, how does one go about this?

Thank you,

Jody Blau

Feb 7 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"jodyblau" <jo******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I have a form with a subform. The form has a button which opens a
dialogbox. I would like the dialog box to call a sub in the subform.
I know how I would do this in C++, but I can't seem to figure it out in
visual basic.

Is this simply a matter of changing the sub to public instead of
private and then using some kind of method to execute the sub? If so,
what is that method? If not, how does one go about this?

Thank you,

Jody Blau

In general terms, what are you trying to do?
It is quite likely you can write all your code in the OnClick event of the
button of the main form. It might be more appropriate to put it in a
separate module ... it depends what you are doing.
Anyway, if your subform is named 'sbfSub1' you can do by using the form
property of this control, e.g. Me.sbfSub1.Form.Requery
Feb 7 '06 #2

P: n/a
What I am trying to do is this: My form has some client data, then the
subform displays hyperlink records to all the documents in that
client's folder.

The parent form launches a dialog which allows the user to select a
document to add to the client folder. Once the document has been
copied into the client folder, the dialog closes, but a record with a
hyperlink has not yet been added to the database.

My subform has a function in it that cycles through the client folder
and adds hyperlink records for each document in the folder, and removes
records if a particular document is nolonger in the folder. (So I
don't think a simple Requery will work for this one)

So my problem, I think, is one of scope. I don't know how to call the
function in the subform from another form. If this was c++ I would
make the function a public member of the class, and would then be able
to call the function that way. I just don't know how to do it with
visual basic.

I haven't really looked into the use of Module's yet. If this is how I
have to resolve this issue, could you give me a simple example?

Thanks,

Jody

Feb 7 '06 #3

P: n/a

"jodyblau" <jo******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
What I am trying to do is this: My form has some client data, then the
subform displays hyperlink records to all the documents in that
client's folder.

The parent form launches a dialog which allows the user to select a
document to add to the client folder. Once the document has been
copied into the client folder, the dialog closes, but a record with a
hyperlink has not yet been added to the database.

My subform has a function in it that cycles through the client folder
and adds hyperlink records for each document in the folder, and removes
records if a particular document is nolonger in the folder. (So I
don't think a simple Requery will work for this one)

So my problem, I think, is one of scope. I don't know how to call the
function in the subform from another form. If this was c++ I would
make the function a public member of the class, and would then be able
to call the function that way. I just don't know how to do it with
visual basic.

I haven't really looked into the use of Module's yet. If this is how I
have to resolve this issue, could you give me a simple example?

Thanks,

Jody

That all seems fairly standard. You put you code in the OnClick event of
the button. Now I don't know what code you have to get the path to the new
document, but I assume you know how to do this.
Once you know the path you then copy the file and if this is succesfull you
add the record to the table. As a final step, you requery the subform. No
code needs to be put anywhere but the main form.
The use of modules in Access allows you to write functions which can be
called from anywhere (any form) in your application. For example, if you
wanted the world's simplest example, you could create a new module and write
a public sub in it, e.g.

Public Sub SayHello()
MsgBox "Hello"
End Sub

Then from any form, you could write Call SayHello() to get this to run.

(It's midnight in the UK and I'm going to bed.)



Feb 8 '06 #4

P: n/a
That is exactly what I had to do. Thank you.

It is these little differences between different programming languages
that are hard to find answers for. So, I realize that this was a
fairly basic question, but I appreciate you taking the time to help me
understand what I needed to know.

Thanks,

Jody Blau

Feb 8 '06 #5

P: n/a
You can also reference the function on the other form if it is public
(I think) by the following:

Form_MyForm.FunctionName(Arguments)

Form_ is standard
MyForm is the name of the form you are calling
FunctionName is the name of the function you are calling
Arguments are the arguments required by the function you are calling

I kind of like to keep the function code in modules and user interface
code (hiding buttons, enabling controls) on forms themselves, I'm not
sure what the overall "preferred" way of doing it is.

Feb 8 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.