473,774 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2329
"jodyblau" <jo******@gmail .com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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******** *************@g 47g2000cwa.goog legroups.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.Fun ctionName(Argum ents)

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
2963
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 p3); The parameters here can be read either in the forward order from p1 till p3 or reverse order from p3 till p1. Can anyone explain what is the advantage/disadvantage of either of
6
3312
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 in VBA from my other Access applications. This works fine and I'm quite happy with it... except for one area; error handling. In most of my functions I call an error handler which
14
3013
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() ' This method shows the form used to get the info If sWhereInt = "" Then DoCmd.OpenForm sFormNameInt, acNormal, , , acFormAdd, _
1
2914
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 written in C#. When the app calls my unmanaged functions, they work fine. But as soon as my unmanaged functions call managed functions (in the same source file!), the app reports an "unknown exception" error.
5
3437
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 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
2
3151
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 the stack pointer and it does it by the command "add esp,8" after returning from the called function. My questions: 1. Is the stack pointer common in a certain thread(or process)? 2. How does the called function get the parameters, is it by...
18
4358
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 can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters, isn't easy. As far as I can see, there are only two solutions: 1) This one is portable. If...
15
22863
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 could either be f1() or f2(). BRs!
11
3201
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 Esa_Init. When I make a call, VS2005 reports "AccessViolationException" and refers to the 4th parameter (EsaT_State_Handle). I don't know how to define nor pass this reference correctly to the legacy DLL. What am I doing wrong? Thanks in...
16
517
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 and my c++ code should call c code.but when i tried to call a function in c code externing that function in my c++ code, i am getting unresolved external symbol error. Whatever i try its giving more and more errrors...so is it possible to merge 2...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.