custom msgbox function

roccoIT

New member
Local time
Today, 05:31
Joined
Jul 6, 2010
Messages
4
Hello,
I'm trying to build a custom msgbox function. In a module I have created a function that will open my custom form the user will use to make his choice. This choice is trapped through a public variable ("answered") Here it is:

Option Compare Database
Public answered As Integer

Public Function MakeQuestion(msgtxt As String) As Integer
DoCmd.OpenForm "frmAsk", , , , , , msgtxt
MakeQuestion = answered
End Function

*****
I will then use the choice made by the user to take different different actions. the TROUBLE is it wont work!
When I call this function on a procedure in another module (not class module, an ordinary module) the code doesn't wait but go straight to the end. her is the code that calls my function:

dim myChoice as integer
myChoice = MakeQuestion("By continuing all of the data inserted in the form will be lost. Continute?")
Select Case myChoice
Case Is = 1
MsgBox "user answered yes"
Set collConsults = New Consults
DoCmd.OpenForm "frmConsulenza1", acNormal
Case Is = 2
MsgBox "ho risposto NO"
Exit Sub
End Select
MsgBox "end of the procedure"

What it happens is that as soon as the custom form ("frmAsk") called by the MakeQuestion function opens you get immediately MsgBox "end of the procedure". What is wrong???
Thanks
Rocco
 
Rocco,

At no point does your code set a value to the 'answered' variable. So it will evaluate by default to 0. And thus neither of the options 1 or 2 in your Select Case code will apply.
 
it does! ... in the frmAsk code. here it is:
Option Compare Database
Private Sub Comando1_Click()
answered = 1
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Private Sub Comando2_Click()
answered = 2
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Private Sub Comando3_Click()
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Private Sub Form_Load()
question.Caption = Me.OpenArgs
End Sub
 
Hi

have you thought about making the variable "answered" public? you might be getting the issue because "answered" in in a private sub and the module cannot collect the answer?

just a thought?



Nidge
 
Thanks for the hint, but it is public... forth line in my first post.
I'm going crazy with this...
 
Hi

i dont quite follow your code as youve only put part of it in.

in the form "frmAsk", you have this code-
Code:
Option Compare Database
Private Sub Comando1_Click()
answered = 1
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Private Sub Comando2_Click()
answered = 2
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Private Sub Comando3_Click()
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
Private Sub Form_Load()
question.Caption = Me.OpenArgs
End Sub

and all this does is set the variable "answered" to either 1 or 2

in a module, you have this code as a function-
Code:
Option Compare Database
Public answered As Integer

Public Function MakeQuestion(msgtxt As String) As Integer
DoCmd.OpenForm "frmAsk", , , , , , msgtxt
MakeQuestion = answered
End Function
this is opening the form "frmAsk" and you set MakeQuestion equal to the variable "answered" but, this variable doesnt seem to be set until after the form frmAsk is open and a selection is made thus MakeQuestion will be null


can you make a test database to post? it would be much easier


nidge
 
Rocco,

Nigel is correct. The 'answered' variable is not available to both routines. If you putr an 'Option Explicit' in the header of your code, you will find you would get an error if you try to compile your code.

If you want it to be a Global variable, it needs to be declared in a Standard Module (i.e. not a form module). Alternatively (and preferably), if you are using Access 2007 or Access 2010, you can use a TempVar.
 
As answered and resolved elsewhere, the OP was missing the acDialog option in the OpenForm.
 

Users who are viewing this thread

Back
Top Bottom