Function Value

  • Thread starter Thread starter Red
  • Start date Start date
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.
 
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'.
 
Back
Top