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
11 6992
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?
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.
What about a message box with a yes or no button. You can capture which button is pressed and act accordingly.
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.
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.
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.
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"
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.
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. -
Public Function GetForm(ByVal strFormName As String) As Access.Form
-
-
For Each frm In Forms
-
If frm.Name = strFormName Then
-
Set GetForm = frm
-
Exit Function
-
Else
-
Set GetForm = ScanFormControls(strFormName, frm.Controls)
-
If Not (GetForm Is Nothing) Then Exit Function
-
End If
-
Next
-
-
End Function
-
-
Private Function ScanFormControls(ByVal strFormToFind As String, _
-
ByRef frmControlsToScan As Controls) As Access.Form
-
-
On Error GoTo NextIteration
-
For Each ctrl In frmControlsToScan
-
If TypeName(ctrl) = "SubForm" Then
-
If ctrl.Form.Name = strFormToFind Then
-
Set ScanFormControls = ctrl.Form
-
Exit Function
-
Else
-
Set ScanFormControls = _
-
ScanFormControls(strFormToFind, ctrl.Form.Controls)
-
If Not (ScanFormControls Is Nothing) Then Exit Function
-
End If
-
End If
-
NextIteration:
-
Next
-
-
End Function
-
BTW another interesting solution.
Let us say you have form "Main" from which you open form "Popup" with two buttons.
Form_Main module: -
Option Compare Database
-
Dim WithEvents frmForm As Form_Popup
-
-
Private Sub Command0_Click()
-
DoCmd.OpenForm "Popup"
-
Set frmForm = Forms!PopUp
-
End Sub
-
-
Private Sub Form_Close()
-
Set frmForm = Nothing
-
End Sub
-
-
Private Sub frmForm_Button1Clicked()
-
MsgBox "Button1 clicked"
-
End Sub
-
-
Private Sub frmForm_Button2Clicked()
-
MsgBox "Button2 clicked"
-
End Sub
-
Form_Popup module: -
Option Compare Database
-
Event Button1Clicked()
-
Event Button2Clicked()
-
-
Private Sub btnButton1_Click()
-
RaiseEvent Button1Clicked
-
End Sub
-
-
Private Sub btnButton2_Click()
-
RaiseEvent Button2Clicked
-
End Sub
-
I hope this nice solution makes a sense.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |