473,785 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing data to modal dialog box in VBA

Hello,

I need to create a custome form that operates similar to the MsgBox()
and InputBox() functions. I can't figure out how to pass data to a
MODAL dialog box (form).

I've tried 3 approaches:

Try #1:

Dim f as MySpecial Form
f = new MySpecialForm
f.SetInputParam eters( ... )
f.Open()

dim result as int
result = f.GetResults()

But of course this didn't work because Forms don't seem to have an
Open() command.

Try #2
Dim m_Input as string
Dim m_Output as integer
static public function Open( intput as string ) as int
m_Input = input
DoCmd.Open "MyForm"
Open = m_Output
end function

but the "global" variables aren't letting me pass values into/outof the
class.

Try #3

DoCmd.Open "MyForm"
Forms[MyForm].Set Parameters

This attempt was just wrong.

How can I pass variables into a MODAL dialog box?
OR
How can I create a form, call some member functions, open it, close it,
call more member functions, then destroy the object?

Very frustrating...

Dean Rettig

Nov 13 '05 #1
5 17278
jv
If the form is not open with the WindowMode=acDi alog then you should be
able to do Forms!MyForm!Co ntrolName=xxxx. Granted that you'll have a
create a form control to hold the data that you are passing in, but
that control doesn't have to be visible.

You can also simply reference the data that is on the main form from
the popup form (i.e. variableName=Fo rms!frmMainForm !ControlName)

Another way is to pass in a string using the OpenArgs parameter of the
Docmd.OpenForm method. Then you'll be able to access it using
Me.OpenArgs from the popup form. The limitation here is that you can
only pass in one string. However, you can concatenate your data with
delimiters and the parse it out from the popup form.

I hope others can come up with better solutions. Good luck.

Nov 13 '05 #2
<re******@bigfo ot.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hello,

I need to create a custome form that operates similar to the MsgBox()
and InputBox() functions. I can't figure out how to pass data to a
MODAL dialog box (form).

I've tried 3 approaches:

Try #1:

Dim f as MySpecial Form
f = new MySpecialForm
f.SetInputParam eters( ... )
f.Open()

dim result as int
result = f.GetResults()

But of course this didn't work because Forms don't seem to have an
Open() command.

Try #2
Dim m_Input as string
Dim m_Output as integer
static public function Open( intput as string ) as int
m_Input = input
DoCmd.Open "MyForm"
Open = m_Output
end function

but the "global" variables aren't letting me pass values into/outof the
class.

Try #3

DoCmd.Open "MyForm"
Forms[MyForm].Set Parameters

This attempt was just wrong.

How can I pass variables into a MODAL dialog box?
OR
How can I create a form, call some member functions, open it, close it,
call more member functions, then destroy the object?

Very frustrating...

Dean Rettig

Like the reply from jv, this idea uses the OpenArgs idea, but gives some
code for parsing out the parameters. In this example, we create a function
similar to InputBox() except that ours uses a custom form. The form has a
textbox 'txtResponse', a label 'lblPrompt' and two command buttons
'cmdCancel and 'cmdOK'. You also need a separate module.
To test it out, try
debug.print MyInputBox("Ple ase enter your surname","Surna me
Missing","Smith ")
' *************** *************** *************** *********
' Code for the form
Option Compare Database
Option Explicit

Private Sub cmdCancel_Click ()

On Error GoTo Err_Handler

DoCmd.Close

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Private Sub cmdOK_Click()

On Error GoTo Err_Handler

Me.Visible = False

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Private Sub Form_Open(Cance l As Integer)

On Error GoTo Err_Handler

Dim strOpenArgs As String
Dim astrValues() As String
Dim strValue As String
Dim lngPosition As Long
Dim lngCount As Long

Cancel = True

strOpenArgs = Nz(Me.OpenArgs, "")

If Len(strOpenArgs ) > 0 Then

astrValues = Split(strOpenAr gs, "|")

For lngCount = 0 To UBound(astrValu es())

strValue = astrValues(lngC ount)

lngPosition = InStr(strValue, "=")

If lngPosition > 1 Then

Select Case UCase(Left$(str Value, lngPosition))

Case "PROMPT="
Me.lblPrompt.Ca ption = Trim(Mid$(strVa lue, lngPosition + 1))

Case "TITLE="
Me.Caption = Trim(Mid$(strVa lue, lngPosition + 1))

Case "DEFAULT="
Me.txtResponse = Trim(Mid$(strVa lue, lngPosition + 1))

End Select

End If

Next lngCount

End If

If lngCount = 3 Then
' The right number of parameters have been passed
Cancel = False
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
' *************** *************** *************** *********
' *************** *************** *************** *********
' Code in a separate module
Option Compare Database
Option Explicit

Public Function MyInputBox(strP rompt As String, _
strTitle As String, _
strDefault As String) As String

On Error GoTo Err_Handler

Dim strReturn As String
Dim strOpenArgs As String

strOpenArgs = "Prompt=" & strPrompt & "|" & _
"Title=" & strTitle & "|" & _
"Default=" & strDefault

DoCmd.OpenForm "frmMyInputBox" , , , , , acDialog, strOpenArgs

If IsFormLoaded("f rmMyInputBox") Then
strReturn = Nz(Forms!frmMyI nputBox.txtResp onse, "")
DoCmd.Close acForm, "frmMyInput Box"
End If

MyInputBox = strReturn

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

Private Function IsFormLoaded(st rName As String)
IsFormLoaded = (SysCmd(acSysCm dGetObjectState , acForm, strName) <> 0)
End Function
' *************** *************** *************** *********
Nov 13 '05 #3
Justin,

I see what you are trying to do. I tried something similar. Did you
try it? Does it work for you?

I tried this but since the box is opened modally (acDialog), the
function stopped executing on that statement until the dialog closed.
Then the function resumed execution at "IsFormLoaded(. ..)" but was too
late to grab the return value because the form was gone..

I've hacked it by storing the parameters in global variables inside a
code module. Its awfully ugly but I guess it works. Yuck!

Dean

Nov 13 '05 #4

<re******@bigfo ot.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Justin,

I see what you are trying to do. I tried something similar. Did you
try it? Does it work for you?

I tried this but since the box is opened modally (acDialog), the
function stopped executing on that statement until the dialog closed.
Then the function resumed execution at "IsFormLoaded(. ..)" but was too
late to grab the return value because the form was gone..

I've hacked it by storing the parameters in global variables inside a
code module. Its awfully ugly but I guess it works. Yuck!

Dean

I did double-check it before I posted it. There is no need for global
variables. I guess you didn't put the code in for the two buttons as
described. There two buttons on the form cmdOK and cmdCancel should do
different things. The cancel button closes the form, so the value is lost
and the function returns an empty string. The OK button sets the form's
visible to false, so the function continues, the value is picked up from the
textbox before the form is actually closed.

Can you double-check what you did? I don't think I made a mistake - but it
has been known in the past!
' *************** *************** *************** *********
' Code for the form
Option Compare Database
Option Explicit

Private Sub cmdCancel_Click ()

On Error GoTo Err_Handler

DoCmd.Close

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Private Sub cmdOK_Click()

On Error GoTo Err_Handler

Me.Visible = False

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Private Sub Form_Open(Cance l As Integer)

On Error GoTo Err_Handler

Dim strOpenArgs As String
Dim astrValues() As String
Dim strValue As String
Dim lngPosition As Long
Dim lngCount As Long

Cancel = True

strOpenArgs = Nz(Me.OpenArgs, "")

If Len(strOpenArgs ) > 0 Then

astrValues = Split(strOpenAr gs, "|")

For lngCount = 0 To UBound(astrValu es())

strValue = astrValues(lngC ount)

lngPosition = InStr(strValue, "=")

If lngPosition > 1 Then

Select Case UCase(Left$(str Value, lngPosition))

Case "PROMPT="
Me.lblPrompt.Ca ption = Trim(Mid$(strVa lue, lngPosition + 1))

Case "TITLE="
Me.Caption = Trim(Mid$(strVa lue, lngPosition + 1))

Case "DEFAULT="
Me.txtResponse = Trim(Mid$(strVa lue, lngPosition + 1))

End Select

End If

Next lngCount

End If

If lngCount = 3 Then
' The right number of parameters have been passed
Cancel = False
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
' *************** *************** *************** *********
' *************** *************** *************** *********
' Code in a separate module
Option Compare Database
Option Explicit

Public Function MyInputBox(strP rompt As String, _
strTitle As String, _
strDefault As String) As String

On Error GoTo Err_Handler

Dim strReturn As String
Dim strOpenArgs As String

strOpenArgs = "Prompt=" & strPrompt & "|" & _
"Title=" & strTitle & "|" & _
"Default=" & strDefault

DoCmd.OpenForm "frmMyInputBox" , , , , , acDialog, strOpenArgs

If IsFormLoaded("f rmMyInputBox") Then
strReturn = Nz(Forms!frmMyI nputBox.txtResp onse, "")
DoCmd.Close acForm, "frmMyInput Box"
End If

MyInputBox = strReturn

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

Private Function IsFormLoaded(st rName As String)
IsFormLoaded = (SysCmd(acSysCm dGetObjectState , acForm, strName) <> 0)
End Function
' *************** *************** *************** *********

Nov 13 '05 #5

<re******@bigfo ot.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Justin,

I see what you are trying to do. I tried something similar. Did you
try it? Does it work for you?

I tried this but since the box is opened modally (acDialog), the
function stopped executing on that statement until the dialog closed.
Then the function resumed execution at "IsFormLoaded(. ..)" but was too
late to grab the return value because the form was gone..

I've hacked it by storing the parameters in global variables inside a
code module. Its awfully ugly but I guess it works. Yuck!

Dean


repost - as it still hasn't appeared on my news server:
I did double-check it before I posted it. There is no need for global
variables. I guess you didn't put the code in for the two buttons as
described. There two buttons on the form cmdOK and cmdCancel should do
different things. The cancel button closes the form, so the value is lost
and the function returns an empty string. The OK button sets the form's
visible to false, so the function continues, the value is picked up from the
textbox before the form is actually closed.

Can you double-check what you did? I don't think I made a mistake - but it
has been known in the past!
' *************** *************** *************** *********
' Code for the form
Option Compare Database
Option Explicit

Private Sub cmdCancel_Click ()

On Error GoTo Err_Handler

DoCmd.Close

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Private Sub cmdOK_Click()

On Error GoTo Err_Handler

Me.Visible = False

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Private Sub Form_Open(Cance l As Integer)

On Error GoTo Err_Handler

Dim strOpenArgs As String
Dim astrValues() As String
Dim strValue As String
Dim lngPosition As Long
Dim lngCount As Long

Cancel = True

strOpenArgs = Nz(Me.OpenArgs, "")

If Len(strOpenArgs ) > 0 Then

astrValues = Split(strOpenAr gs, "|")

For lngCount = 0 To UBound(astrValu es())

strValue = astrValues(lngC ount)

lngPosition = InStr(strValue, "=")

If lngPosition > 1 Then

Select Case UCase(Left$(str Value, lngPosition))

Case "PROMPT="
Me.lblPrompt.Ca ption = Trim(Mid$(strVa lue, lngPosition + 1))

Case "TITLE="
Me.Caption = Trim(Mid$(strVa lue, lngPosition + 1))

Case "DEFAULT="
Me.txtResponse = Trim(Mid$(strVa lue, lngPosition + 1))

End Select

End If

Next lngCount

End If

If lngCount = 3 Then
' The right number of parameters have been passed
Cancel = False
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
' *************** *************** *************** *********
' *************** *************** *************** *********
' Code in a separate module
Option Compare Database
Option Explicit

Public Function MyInputBox(strP rompt As String, _
strTitle As String, _
strDefault As String) As String

On Error GoTo Err_Handler

Dim strReturn As String
Dim strOpenArgs As String

strOpenArgs = "Prompt=" & strPrompt & "|" & _
"Title=" & strTitle & "|" & _
"Default=" & strDefault

DoCmd.OpenForm "frmMyInputBox" , , , , , acDialog, strOpenArgs

If IsFormLoaded("f rmMyInputBox") Then
strReturn = Nz(Forms!frmMyI nputBox.txtResp onse, "")
DoCmd.Close acForm, "frmMyInput Box"
End If

MyInputBox = strReturn

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function

Private Function IsFormLoaded(st rName As String)
IsFormLoaded = (SysCmd(acSysCm dGetObjectState , acForm, strName) <> 0)
End Function
' *************** *************** *************** *********
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5808
by: Matt | last post by:
I want to post the form data (http://server/page1.asp) to a modal dialog window (http://server/modaldialog.asp) with a desired height 200px by width 200px. Here's my attempts and problems: Attempt #1) In http://server/page1.asp, it has code <form action="http://server/modaldialog.asp" method="post" target="_blank"> In http://server/modaldialog.asp, it has code <body onBlur = "self.focus()">
2
6521
by: Matt | last post by:
I reposted this question because I really want to accomplish this task. Please advise!! I want to post the form data (http://server/page1.asp) to a modal dialog window (http://server/modaldialog.asp) with a desired height 200px by width 200px. Here's my attempts and problems:
2
6734
by: Gilles T. | last post by:
Hi, How I can refresh a modal dialog in asp.net? I open a modal dialog in first with a dropdownlist. To add a element in my dropdownlist (table), I open a second modal dialog to ask element and save. When I return in my first modal dialog, dropdownlist is not refreshed. I don't know how to refresh my first modal dialog to view my new element in the dropdownlist. Thanks to help me with this problem!
4
1691
by: Job Lot | last post by:
How would I send information from DataGrid on the main form of the application to a modal popup form and then pass any changes to the data back to the main form and database when the popup form was closed? Thanks
2
3884
by: Matt | last post by:
I want to know how to submit the form data to a modal dialog window? The following is page1.asp, and when the user clicks submit button, it will post the form data to page2.asp by opening a new window. But I want modal dialog window, any ideas?? <form action="page2.asp" method="post" target="_blank"> <input type="text" name="username"> <input type="submit" name="submit"> </form>
2
7089
by: John | last post by:
Hi all, I have a modal dialog window from which a user selects a few rows from a datagrid and then clicks on an image button. My question is two-fold: 1. How do I post data back to the same dialog window? 2. The dialog window in question was, in turn, created from a dialog window. I need to post data back to that one too (that which the user selected in the top-most dialog window). How do I send data back to this window?
10
2756
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a preview DIV) 2. when users close the dialog, the application receives the URL to the selected graphic. 3. the modal dialog lets the users upload a new graphic if the dialog does not present them with one they are already happy with. 4. upon uploading...
1
2174
by: Carlos Alejandro Pérez | last post by:
hi I need to perform this sequence: - a webform A calls another webform B. Webform B should be a modal one - when data is entered in webform B, the user chooses close window - the data must be captured and processed by webform A, if possible, *without* clicking on a button to force this. I know I should use IFrames. Can any1 here give me a clue regarding this? Can the application object be used to fire events automatically in webform A...
0
9645
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
9480
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
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9949
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
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
6739
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.