Use of Flag field across all events

S

stickandrock

I have an error flag that I want to use on a form.

I want to set flag on through error checks done on different events

I am then checking for this flag when the form is closed, but it doesn't
reconize the value on set while in an event.

so how do I set a field to be used publicly in any event on a form?

Thanks for any and all input.
 
A

Arvin Meyer [MVP]

Dim the flag in the Declarations section of a form's code module, like.

Public blFlag As Boolean
or
Dim blFlag As Boolean
or
Static blFlag As Boolean

Then set the flag in your subroutine. It's a good idea to clear it when
closing the form>

Public Sub Form_Close()
blFlag = Null
End Sub
 
S

stickandrock

That is was I was thinking but here is some of my code....
Option Explicit
Dim errflg As String
errflg = "no"

Public Sub Command27_Click()
On Error GoTo Err_Command27_Click
MsgBox (errflg)

If (errflg = "no") Then
DoCmd.Close
End If


Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub


My msgbox shows as a null
 
D

Douglas J. Steele

You can't assign values to variables outside of a module.

Move the line

errflag = "no"

into the form's Load event.

(and just being picky, your message box couldn't have shown a Null: string
variables cannot contain Nulls (only Variants can). It would have been
showing a zero-length string (""))

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 
S

stickandrock

abolutely correct

Douglas J. Steele said:
You can't assign values to variables outside of a module.

Move the line

errflag = "no"

into the form's Load event.

(and just being picky, your message box couldn't have shown a Null: string
variables cannot contain Nulls (only Variants can). It would have been
showing a zero-length string (""))
 

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