473,420 Members | 1,618 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,420 software developers and data experts.

Pass a form reference to a form...

This is a complicated one...

I have a modal form that lets the user preview some text, then either click Submit or Close. This form is called from several other forms.

What I would like, since Access can't return a value from a form, is to set (from the modal form) a hidden checkbox on the calling form, which would show which button the user pressed on the modal form.

My problem is this -- how can I pass the name of the calling form (which may be a subform) to the modal form, so I can set the checkbox on the calling form.

I've thought to just pass Me.Name, and then in the modal form, using Forms(Me.OpenArgs).chkRetval... but when calling from a subform, that fails. I've also considered setting a flag on the modal form, hiding it, reading the flag from the calling form and then closing the modal form, but that seems messy, so it's a last resort.

Any thoughts?

Thanks
Aug 29 '07 #1
11 6992
JKing
1,206 Expert 1GB
I'm a little confused as why you would need to capture which button has been clicked? Why not just add the relevant code to the onclick of the button rather than perform the actions from another forms module?
Aug 29 '07 #2
I'm a little confused as why you would need to capture which button has been clicked? Why not just add the relevant code to the onclick of the button rather than perform the actions from another forms module?
This form allows the user to preview some text before writing it out to another database. I need to know if the user published the text or closed the form without publishing. Based on that, the calling form will either update a "published date" or not. It's a lot cleaner if the calling form takes care of writing that date, instead of the modal form because the published date will not always be in the same table.
Aug 29 '07 #3
JKing
1,206 Expert 1GB
What about a message box with a yes or no button. You can capture which button is pressed and act accordingly.
Aug 29 '07 #4
What about a message box with a yes or no button. You can capture which button is pressed and act accordingly.
The text will typically be too much for a msgbox. Plus, the user wants to be able to edit the text in the preview window.. which means it isn't actually a preview anymore, but the changes made won't be reflected in the local database -- just pushed to the sql server.

It's a complicated thing.
Aug 29 '07 #5
JKing
1,206 Expert 1GB
How about creating a global string variable. On submit click the "preview"text is stored in the string on close click the string is set to "".

Then the other form can check the string if it's null do nothing, if its not null send the text to the appropriate location.
Aug 29 '07 #6
I try to avoid global vars at all costs in Access.. I hate them almost as much as Goto's.. hehe

I think I'll just go with my Plan B until a better idea comes along.. on clicking either button, set a hidden flag on the modal form, hide the form, read the flag from the calling form and then close the modal form.

Thanks for the replies.
Aug 29 '07 #7
Denburt
1,356 Expert 1GB
If I understand correctly I have utilized something similar in the past but i use the tag. When you Open the Modal dialog box insert the calling forms name into the tag. Now you know what form originally called the modal form. When you close the modal form call the modal forms tag like so.

Open the modal form:
Docmd.openform "ModalBtch"
Forms!ModalBtch.Tag = me.name

Then on closing the modal form you specify the button clicked and assign it to the calling forms tag like so.

Forms(me.tag).tag = "Print"
Aug 29 '07 #8
If I understand correctly I have utilized something similar in the past but i use the tag. When you Open the Modal dialog box insert the calling forms name into the tag. Now you know what form originally called the modal form. When you close the modal form call the modal forms tag like so.

Open the modal form:
Docmd.openform "ModalBtch"
Forms!ModalBtch.Tag = me.name

Then on closing the modal form you specify the button clicked and assign it to the calling forms tag like so.

Forms(me.tag).tag = "Print"
Thanks for the thought, but (as far as I can figure), this wouldn't work with subforms.. Unless I set the parent form's Tag property, but then I'd need to pass Me.Parent.Name.. this is getting messy.
Aug 29 '07 #9
FishVal
2,653 Expert 2GB
Thanks for the thought, but (as far as I can figure), this wouldn't work with subforms.. Unless I set the parent form's Tag property, but then I'd need to pass Me.Parent.Name.. this is getting messy.
Hi, there.

This simple code will help you to get reference to Form object by name no matter it was openes as main form or as subform with any possible level of nesting.

Expand|Select|Wrap|Line Numbers
  1. Public Function GetForm(ByVal strFormName As String) As Access.Form
  2.  
  3.     For Each frm In Forms
  4.         If frm.Name = strFormName Then
  5.             Set GetForm = frm
  6.             Exit Function
  7.         Else
  8.             Set GetForm = ScanFormControls(strFormName, frm.Controls)
  9.             If Not (GetForm Is Nothing) Then Exit Function
  10.         End If
  11.     Next
  12.  
  13. End Function
  14.  
  15. Private Function ScanFormControls(ByVal strFormToFind As String, _
  16.                                   ByRef frmControlsToScan As Controls) As Access.Form
  17.  
  18.     On Error GoTo NextIteration
  19.     For Each ctrl In frmControlsToScan
  20.         If TypeName(ctrl) = "SubForm" Then
  21.             If ctrl.Form.Name = strFormToFind Then
  22.                 Set ScanFormControls = ctrl.Form
  23.                 Exit Function
  24.             Else
  25.                 Set ScanFormControls = _
  26.                     ScanFormControls(strFormToFind, ctrl.Form.Controls)
  27.                 If Not (ScanFormControls Is Nothing) Then Exit Function
  28.             End If
  29.         End If
  30. NextIteration:
  31.     Next
  32.  
  33. End Function
  34.  
Aug 29 '07 #10
FishVal
2,653 Expert 2GB
BTW another interesting solution.

Let us say you have form "Main" from which you open form "Popup" with two buttons.

Form_Main module:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Dim WithEvents frmForm As Form_Popup
  3.  
  4. Private Sub Command0_Click()
  5.     DoCmd.OpenForm "Popup"
  6.     Set frmForm = Forms!PopUp
  7. End Sub
  8.  
  9. Private Sub Form_Close()
  10.     Set frmForm = Nothing
  11. End Sub
  12.  
  13. Private Sub frmForm_Button1Clicked()
  14.     MsgBox "Button1 clicked"
  15. End Sub
  16.  
  17. Private Sub frmForm_Button2Clicked()
  18.     MsgBox "Button2 clicked"
  19. End Sub
  20.  
Form_Popup module:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Event Button1Clicked()
  3. Event Button2Clicked()
  4.  
  5. Private Sub btnButton1_Click()
  6.     RaiseEvent Button1Clicked
  7. End Sub
  8.  
  9. Private Sub btnButton2_Click()
  10.     RaiseEvent Button2Clicked
  11. End Sub
  12.  
I hope this nice solution makes a sense.
Aug 29 '07 #11
Wow -- Go Go FishVal !

First off, the functions to return a form ref are awesome.. thank you.

And I didn't even know about declaring Events.. so thanks and kudos all-round.
Aug 31 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
11
by: Vanessa | last post by:
Hi, I would like to know whether there's any way for me to pass an object by reference to another form? Regards Vanessa
12
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though,...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
3
by: DCB | last post by:
Hello. I have an easy question, likely, that has me in a headspin. I have an include file to a frames based site that basically forces frames on the end user if they visit the site and hit a...
4
by: Omar Llanos | last post by:
Recently, I posted a question on how to invoke a textbox control in Form1 (parent form) from within Form2 (which is inherited from Form1). Someone suggested to pass a reference of the Form1 to the...
4
by: Vaughn | last post by:
When I pass a reference to my current form, frm_x, when I create and show another form, frm_y, do I have access to all of the public methods, controls, members, etc.. of frm_x from frm_y? In my...
2
by: Chane | last post by:
hi i have doubt in how to pass values back to the called form. I have two forms, each having a textbox and a button control. First i'm run the first form and click the button, it creates object...
7
by: forest demon | last post by:
all i want is to do is to pass a form reference to a separate class and be able to manipulate properties/components/controls of said form. this should be as simple as passing a TextBox, Container...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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:
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.