HELP! Obtaining and passing values through modules

  • Thread starter Thread starter Xyon
  • Start date Start date
X

Xyon

Hello EveryOne,

I have a custom message box form which it does what it
says, it substitutes the already built-in MsgBox. At the
moment the form is call from any given form through a
standard module function.

------------------------------

''' begin Function basCustomMsgBox Module
Option Compare Database
Option Explicit

Private Const stMsgBoxForm = "frmCustomMsgBox"
'opens the custom message box with it's appropriate
'message ID #
Public Sub srOpenCustomMsgBox(stCustomMsgID As String)
DoCmd.OpenForm stCustomMsgBoxName, acNormal, ,
stCustomMsgID
End Sub
'obtain response from custom message box and do
'events based on value.
'this is the part I can't seem to figure out. HELP!!!
'the code works I, just don't know how to pass the
'vaules to the calling form
Function fResponse(intResponse As Integer) As Integer
fResponse = intResponse
Select Case fResponse
Case 1
MsgBox "Yes" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 2
MsgBox "No" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 3
'keep on checking until answer is "Yes" or "No"
End Select
End Sub
'''end Function code
------------------------------

The custom message box has the following code:

------------------------------
'''begin frmCustomMsgBox code
Private Sub Form_Load()
'code to animate the form to open from bottom to top
'on the bottom-right corner of Acess, this works fine.
End Sub
'define variable for the fResponse Function
Private Sub optMsgBoxResponse_AfterUpdate()
mdCustomMsgBox.fResponse (Me.optMsgBoxResponse)
End Sub
'''end code

------------------------------

The custom message box has an acOptionGroup
control. Once the form is open the user can select the
appropriate action (eg. Yes(1), No(2)). All forms have a
way to call the custom message box. Depending on the
situation, the form calls the message box and displays the
appropriate message from "tblCustomMsgBox" and it's call
in the following way:

------------------------------

'''begin CallingForm code
Private cmdQuitApp_Click()
Me!Visible = False
Call srOpenCustomMsgBox("[sysMsgID] = 2")
'This is where I get stuck. I need to know what the
'user selects and based on that do the following
If 'user selects selects "Yes(1)" Then
DoCmd.Quit
ElseIf 'user selects "No(2)" then
Me.Visible = True
ElseIf 'user has not choosen then
'Continue checking until user selects an option
End If
End Sub
'''end code

------------------------------

Is there a better way to accomplish my task ? Am I
overlooking something ? If the above made sense, please
help. Thank you all in advance.

Xyon G. Kinkay
 
If I've understood correctly, you want to open the message box form, get it
to display a message and then return a value based on whether the user
clicked "Yes" or "No". The best way to do this (according to the Access Dev
Handbook, not me) is:

- open the form in dialog mode which causes your code to pause until the
form is closed or hidden.
- have one button on the form that closes it ("No" in your case) and one
that hides it ("No")
- check if the form is still open in the line following the line that opened
the form - if it's still open the user clicked "Yes" - you can then retrieve
any other data that may have been entered on the form.

So, you need your form with the two command buttons, and code in the form
open event to display a message based on the OpenArgs. The ADH recommends
creating public properties to make retrieval of data simpler, but you can
also refer to the names of form controls. In your case I think you just want
to know if "Yes" or "No" has been selected.

You then need a CustomMessageBox function, something like this:

Public Function CustomMessageBox(strMessage as String) As Boolean
DoCmd.OpenForm stMsgBoxForm,acNormal,,,,acDialog,strMessage
If CurrentProject.AllForms(stMsgBoxForm).IsLoaded Then
'Form is hidden, user selected "Yes"
CustomMessageBox = True
DoCmd.Close acForm,stMsgBoxForm
Else
'User selected "No"
CustomMessageBox = False
End if
End Function

To use this in your code you just need to put something like:

If CustomMessageBox("Message text") Then
'Do what you want if user clicked yes
Else
'Do what you want if user clicked no
End if

Xyon said:
Hello EveryOne,

I have a custom message box form which it does what it
says, it substitutes the already built-in MsgBox. At the
moment the form is call from any given form through a
standard module function.

------------------------------

''' begin Function basCustomMsgBox Module
Option Compare Database
Option Explicit

Private Const stMsgBoxForm = "frmCustomMsgBox"
'opens the custom message box with it's appropriate
'message ID #
Public Sub srOpenCustomMsgBox(stCustomMsgID As String)
DoCmd.OpenForm stCustomMsgBoxName, acNormal, ,
stCustomMsgID
End Sub
'obtain response from custom message box and do
'events based on value.
'this is the part I can't seem to figure out. HELP!!!
'the code works I, just don't know how to pass the
'vaules to the calling form
Function fResponse(intResponse As Integer) As Integer
fResponse = intResponse
Select Case fResponse
Case 1
MsgBox "Yes" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 2
MsgBox "No" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 3
'keep on checking until answer is "Yes" or "No"
End Select
End Sub
'''end Function code
------------------------------

The custom message box has the following code:

------------------------------
'''begin frmCustomMsgBox code
Private Sub Form_Load()
'code to animate the form to open from bottom to top
'on the bottom-right corner of Acess, this works fine.
End Sub
'define variable for the fResponse Function
Private Sub optMsgBoxResponse_AfterUpdate()
mdCustomMsgBox.fResponse (Me.optMsgBoxResponse)
End Sub
'''end code

------------------------------

The custom message box has an acOptionGroup
control. Once the form is open the user can select the
appropriate action (eg. Yes(1), No(2)). All forms have a
way to call the custom message box. Depending on the
situation, the form calls the message box and displays the
appropriate message from "tblCustomMsgBox" and it's call
in the following way:

------------------------------

'''begin CallingForm code
Private cmdQuitApp_Click()
Me!Visible = False
Call srOpenCustomMsgBox("[sysMsgID] = 2")
'This is where I get stuck. I need to know what the
'user selects and based on that do the following
If 'user selects selects "Yes(1)" Then
DoCmd.Quit
ElseIf 'user selects "No(2)" then
Me.Visible = True
ElseIf 'user has not choosen then
'Continue checking until user selects an option
End If
End Sub
'''end code

------------------------------

Is there a better way to accomplish my task ? Am I
overlooking something ? If the above made sense, please
help. Thank you all in advance.

Xyon G. Kinkay
 
Thank you for the reply,

My message box has the property BorderStyle = "NONE". The
problem is that the acDialog property changes the
BorderStyle to "THIN", which defeats the purpose of the
custom message box. Is there any other way ?

Xyon
-----Original Message-----
If I've understood correctly, you want to open the message box form, get it
to display a message and then return a value based on whether the user
clicked "Yes" or "No". The best way to do this (according to the Access Dev
Handbook, not me) is:

- open the form in dialog mode which causes your code to pause until the
form is closed or hidden.
- have one button on the form that closes it ("No" in your case) and one
that hides it ("No")
- check if the form is still open in the line following the line that opened
the form - if it's still open the user clicked "Yes" - you can then retrieve
any other data that may have been entered on the form.

So, you need your form with the two command buttons, and code in the form
open event to display a message based on the OpenArgs. The ADH recommends
creating public properties to make retrieval of data simpler, but you can
also refer to the names of form controls. In your case I think you just want
to know if "Yes" or "No" has been selected.

You then need a CustomMessageBox function, something like this:

Public Function CustomMessageBox(strMessage as String) As Boolean
DoCmd.OpenForm
stMsgBoxForm,acNormal,,,,acDialog,strMessage
If CurrentProject.AllForms(stMsgBoxForm).IsLoaded Then
'Form is hidden, user selected "Yes"
CustomMessageBox = True
DoCmd.Close acForm,stMsgBoxForm
Else
'User selected "No"
CustomMessageBox = False
End if
End Function

To use this in your code you just need to put something like:

If CustomMessageBox("Message text") Then
'Do what you want if user clicked yes
Else
'Do what you want if user clicked no
End if

Hello EveryOne,

I have a custom message box form which it does what it
says, it substitutes the already built-in MsgBox. At the
moment the form is call from any given form through a
standard module function.

------------------------------

''' begin Function basCustomMsgBox Module
Option Compare Database
Option Explicit

Private Const stMsgBoxForm = "frmCustomMsgBox"
'opens the custom message box with it's appropriate
'message ID #
Public Sub srOpenCustomMsgBox(stCustomMsgID As String)
DoCmd.OpenForm stCustomMsgBoxName, acNormal, ,
stCustomMsgID
End Sub
'obtain response from custom message box and do
'events based on value.
'this is the part I can't seem to figure out. HELP!!!
'the code works I, just don't know how to pass the
'vaules to the calling form
Function fResponse(intResponse As Integer) As Integer
fResponse = intResponse
Select Case fResponse
Case 1
MsgBox "Yes" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 2
MsgBox "No" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 3
'keep on checking until answer is "Yes" or "No"
End Select
End Sub
'''end Function code
------------------------------

The custom message box has the following code:

------------------------------
'''begin frmCustomMsgBox code
Private Sub Form_Load()
'code to animate the form to open from bottom to top
'on the bottom-right corner of Acess, this works fine.
End Sub
'define variable for the fResponse Function
Private Sub optMsgBoxResponse_AfterUpdate()
mdCustomMsgBox.fResponse (Me.optMsgBoxResponse)
End Sub
'''end code

------------------------------

The custom message box has an acOptionGroup
control. Once the form is open the user can select the
appropriate action (eg. Yes(1), No(2)). All forms have a
way to call the custom message box. Depending on the
situation, the form calls the message box and displays the
appropriate message from "tblCustomMsgBox" and it's call
in the following way:

------------------------------

'''begin CallingForm code
Private cmdQuitApp_Click()
Me!Visible = False
Call srOpenCustomMsgBox("[sysMsgID] = 2")
'This is where I get stuck. I need to know what the
'user selects and based on that do the following
If 'user selects selects "Yes(1)" Then
DoCmd.Quit
ElseIf 'user selects "No(2)" then
Me.Visible = True
ElseIf 'user has not choosen then
'Continue checking until user selects an option
End If
End Sub
'''end code

------------------------------

Is there a better way to accomplish my task ? Am I
overlooking something ? If the above made sense, please
help. Thank you all in advance.

Xyon G. Kinkay


.
 
Try putting the code into a loop after you open the form, and check from
time to time to see if the form is still loaded and visible:

Dim i as integer

'code to open form

Do
i = i + 1
If i > 1000 Then '1000 may not be the best value
i = 0
DoEvents
If Not CurrentProject.AllForms(stMsgBoxForm).IsLoaded Then
Exit Do
ElseIf Forms(stMsgBoxform).Visible = False Then
Exit Do
End If
End If
Loop

'rest of code

Xyon said:
Thank you for the reply,

My message box has the property BorderStyle = "NONE". The
problem is that the acDialog property changes the
BorderStyle to "THIN", which defeats the purpose of the
custom message box. Is there any other way ?

Xyon
-----Original Message-----
If I've understood correctly, you want to open the message box form, get it
to display a message and then return a value based on whether the user
clicked "Yes" or "No". The best way to do this (according to the Access Dev
Handbook, not me) is:

- open the form in dialog mode which causes your code to pause until the
form is closed or hidden.
- have one button on the form that closes it ("No" in your case) and one
that hides it ("No")
- check if the form is still open in the line following the line that opened
the form - if it's still open the user clicked "Yes" - you can then retrieve
any other data that may have been entered on the form.

So, you need your form with the two command buttons, and code in the form
open event to display a message based on the OpenArgs. The ADH recommends
creating public properties to make retrieval of data simpler, but you can
also refer to the names of form controls. In your case I think you just want
to know if "Yes" or "No" has been selected.

You then need a CustomMessageBox function, something like this:

Public Function CustomMessageBox(strMessage as String) As Boolean
DoCmd.OpenForm
stMsgBoxForm,acNormal,,,,acDialog,strMessage
If CurrentProject.AllForms(stMsgBoxForm).IsLoaded Then
'Form is hidden, user selected "Yes"
CustomMessageBox = True
DoCmd.Close acForm,stMsgBoxForm
Else
'User selected "No"
CustomMessageBox = False
End if
End Function

To use this in your code you just need to put something like:

If CustomMessageBox("Message text") Then
'Do what you want if user clicked yes
Else
'Do what you want if user clicked no
End if

Hello EveryOne,

I have a custom message box form which it does what it
says, it substitutes the already built-in MsgBox. At the
moment the form is call from any given form through a
standard module function.

------------------------------

''' begin Function basCustomMsgBox Module
Option Compare Database
Option Explicit

Private Const stMsgBoxForm = "frmCustomMsgBox"
'opens the custom message box with it's appropriate
'message ID #
Public Sub srOpenCustomMsgBox(stCustomMsgID As String)
DoCmd.OpenForm stCustomMsgBoxName, acNormal, ,
stCustomMsgID
End Sub
'obtain response from custom message box and do
'events based on value.
'this is the part I can't seem to figure out. HELP!!!
'the code works I, just don't know how to pass the
'vaules to the calling form
Function fResponse(intResponse As Integer) As Integer
fResponse = intResponse
Select Case fResponse
Case 1
MsgBox "Yes" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 2
MsgBox "No" 'display what was choosen
DoCmd.Close acForm, stCustomMsgBoxName
Case 3
'keep on checking until answer is "Yes" or "No"
End Select
End Sub
'''end Function code
------------------------------

The custom message box has the following code:

------------------------------
'''begin frmCustomMsgBox code
Private Sub Form_Load()
'code to animate the form to open from bottom to top
'on the bottom-right corner of Acess, this works fine.
End Sub
'define variable for the fResponse Function
Private Sub optMsgBoxResponse_AfterUpdate()
mdCustomMsgBox.fResponse (Me.optMsgBoxResponse)
End Sub
'''end code

------------------------------

The custom message box has an acOptionGroup
control. Once the form is open the user can select the
appropriate action (eg. Yes(1), No(2)). All forms have a
way to call the custom message box. Depending on the
situation, the form calls the message box and displays the
appropriate message from "tblCustomMsgBox" and it's call
in the following way:

------------------------------

'''begin CallingForm code
Private cmdQuitApp_Click()
Me!Visible = False
Call srOpenCustomMsgBox("[sysMsgID] = 2")
'This is where I get stuck. I need to know what the
'user selects and based on that do the following
If 'user selects selects "Yes(1)" Then
DoCmd.Quit
ElseIf 'user selects "No(2)" then
Me.Visible = True
ElseIf 'user has not choosen then
'Continue checking until user selects an option
End If
End Sub
'''end code

------------------------------

Is there a better way to accomplish my task ? Am I
overlooking something ? If the above made sense, please
help. Thank you all in advance.

Xyon G. Kinkay


.
 
Back
Top