473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Calling a function

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
5 2311
"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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
6
by: jchao123 | last post by:
Dear All, I have an MDB file (Access 2000/XP) which contains generic routines I use in various apps (eg, API calls, File access classes etc). I have compiled into an MDE file which I reference...
14
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() '...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
15
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which...
11
by: briankirkpatrick | last post by:
Forgive me if my post seems a little amateurish... I'm requesting assistance from some of you smart folks out there to get the managed calls write that meet the specification in the esa.h for...
16
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.