Function Value

R

Red

I'd really appreciate some help, I just can't work out what I've done wrong.
I written the below function to return a value to a form, but for some
reason the value doesn't get through.

Public Function Confirm(strMessage As String) As Boolean

myChoice = MsgBox(strMessage, vbQuestion + vbOKCancel, _
"Creating Monthly Movement Table")

End Function


The form code reads:

If Confirm("Are you sure you want to create/overwrite the Monthly
Movement" & Chr(13) & Chr(10) _
& "table for the reporting period " & txtMonth & "/" & strShortYear)
= 2 Then
DoCmd.Close
End
Else
...........................


Thanks.
 
S

Sandra Daigle

Hi Red,

You have to assign the value to the function itself:

Public Function Confirm(strMessage As String) As Boolean

'Notice that the function result is assigned to the function name

Confirm = MsgBox(strMessage, vbQuestion + vbOKCancel, _
"Creating Monthly Movement Table")

End Function

In this case you don't really need a separate function - just test the
results of the msgbox function - also you can use vbCRLF instead of the
separate vbCR & vbLF:

If Msgbox("Are you sure you want to create/overwrite the Monthly Movement"
_
& vbcrlf & "table for the reporting period " & txtMonth & "/" _
& strShortYear, vbQuestion+vbOkCancel, _
"Creating Monthly Movement Table")=vbOK Then
DoCmd.Close
Else
'whatever
endif

I also took out the End within the If structure since it is usually best to
have a single exit/end within a procedure. Let your control structures
determine the flow of execution. In other words, if everything else happens
within the Else clause, the procedure will end after the user chooses 'OK'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top