Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return value from OpenForm Method 1

Status
Not open for further replies.

FoxProProgrammer

Programmer
Apr 26, 2002
967
US
Is there a way to return a value from frm_MultipleID after opening it with:

Code:
DoCmd.OpenForm "frm_MultipleID", , , , , , sendArgs

frm_MultipleID has three buttons: Yes, No, Help. I need to know if the user pressed Yes or No after returning to the calling program.

The MsgBox function won't work because the form has a lot more on it than just a simple prompt. I don't want to include the code that runs when the user presses Yes or No on frm_MultipleID because all the data that I need to process is on the calling form. The form frm_MultipleID is used to confirm changes to the database before they are made. One thing that I though of is to include a hidden field on the calling program, and set the value depending on which button is pressed. This is kind of a trick, and I was hoping that there's a cleaner way to return a value to a calling form.

Thanks!

dz
dzaccess@yahoo.com
 
You may consider a Public variable in the calling form you can use as any property of this form in frm_MultipleID.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Good idea, PH, but I forgot where to declare Public variables.

I included the following code in the General Declarations section of the calling form. That didn't work, I guess because it needs to be at the project level.

Code:
Public whichBtn As Integer

I set the value of whichBtn in the On Click Procedures (btnYes and btnNo) of frm_MultipleID. Now I just need to know where to declare Public variables and I'll be on my way. By the way, I once heard that the use of Public variables wasn't preferred. Do you agree with this, and if so, can you think of any other way to return a value to a calling form?

Thanks again.

dz
dzaccess@yahoo.com
 
I set the value of whichBtn in the On Click Procedures (btnYes and btnNo) of frm_MultipleID
How did you that, like this ?
Forms![calling form].whichBtn = vbYes

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
No, I didn't set it like that. Now I'm a bit confused.

The calling form is named frm_addComponents. I open frm_multipleID in the On Click Procedure of the Save button of frm_addComponents. The user confirms the changes the table on frm_multipleID and clicks one of three buttons: Yes, No, Help. If they click Help, I display a help screen. If they click Yes or No, I want to return to frm_addComponents with a value that tells me which button was clicked. To do this, I tried to define a Public variable in the General Declarations area of frm_multipleID. The variable is named whichBtn and is defined as an Integer. I set the value of whichBtn in the On Click Procedure of btn_yes and btn_no. If the user clicks btn_yes, I set the value of whichBtn to 1. If the user clicks btn_no, I set the value of whichBtn to 0.

Control returns to frm_addComponents. Immediately after DoCmd.OpenForm "frm_multipleID"..., I check the value of whichBtn. The value is empty. I checked the value of whichBtn before frm_multipleID finished running and it was set to 1 when I clicked Yes. So, it doesn't appear as if the Public declaration is working.

Does frm_multipleID have to be open for this to work?

Where do I Dim the Public variable? I tried declaring it in the General Declarations area of frm_addComponents, frm_multipleID, and both those forms. It doesn't make sense to me that a Public variable would be defined in two places. That's what makes me think that I'm not declaring it in the right place.

Thanks,

Dan

dz
dzaccess@yahoo.com
 
Declare the public variable in the General Declarations of frm_addComponents ONLY and then in the in the btnYes Click event procedure:
Forms![frm_addComponents].whichBtn = 1
BTW, open frm_multipleID as modal (acDialog)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, PH. That works now. I suppose that I will need to declare whichBtn in the General Declarations area of each form that will use that data? If so, I don't really understand why it is structured that way. It seems like a Public variable should be defined once for the entire project, but it doesn't look like there's a place to define variables that are global to the project. I'd greatly appreciate if you could confirm this.

You mentioned that I should open the form as modal. I actually opened it as modal until it caused another problem. To keep this thread clean, I'll start a new thread for that problem.

Thanks again,



dz
dzaccess@yahoo.com
 
A Public variable declared in the Class module of a form is like a property of THIS form.
A Public variable declared in a standard code module is available for the entire project.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
<A Public variable declared in a standard code module is available for the entire project.>

Why then does the form in which the Public variable is declared matter? Why couldn't I declare it in an arbitrary form's General Declaration? Or maybe I don't understand what you mean by "Class module" and "standard code module". By "standard code module" do you mean the area at the very top of a module that says "General Declarations", and by Class module, do you mean any code below the General Declarations, for example, specific event procedures?

Thanks!

dz
dzaccess@yahoo.com
 
To create a standard code module go to VBE (Ctrl+G), menu Insert -> Module
You may now write code available for the entire project, ie not related to any form or report.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ah, I had forgotten how to create a standard code module. I had defined whichBtn in the General Declarations section of frm_addComponents.

I created a standard code module, moved the Public declaration for whichBtn there, and changed the way it is set from Forms![frm_addComponents].whichBtn = 1
to simply whichBtn = 1. It works great. Thanks again.

dz
dzaccess@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top