Re: Boolean variable not holding state



"Douglas J. Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxxx> wrote in
news:u2mBXrntIHA.4912@xxxxxxxxxxxxxxxxxxxx:

"Bob Quintal" <rquintal@xxxxxxxxxxxxx> wrote in message
news:Xns9A9EC6666D5B8BQuintal@xxxxxxxxxxxxxxx
"Douglas J. Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxxx> wrote in
news:ejE5vSgtIHA.4772@xxxxxxxxxxxxxxxxxxxx:

You've declared validate inside of btnSaveRecord_Click. That
means you can only refer to that variable inside that routine.

To declare a variable that can be used by all routines within
the module, declare the variable at the top of the module before
any code.

The fact, though, that you're not getting an error implies that
you haven't told Access to require that all variables be
declared. Go into the VB Editor and select Tools | Options from
the menu. Make sure that the "Require Variable Declaration" box
is checked on the Editor tab. If you had done that, then you'd
have quickly realized that your sub validateAccount knew nothing
about the variable validate.

Even with Option Explicit the sub does not generate any error.

The reason he's not getting an error is that he's used the
implicitly defined variant validate in the function by treating
it as a parameter.

The actual problem is that he's put validate inside parentheses,
and I don't know why, but that seems to prevent the call from
changing the variable
'This works:
validateAccount validate
'This does not:
validateAccount (validate)

Sorry, you're right Bob. I missed the fact that he was calling the
second sub from the first.

The reason it doesn't work is that putting parentheses around the
argument changes how you pass from the default ByRef to ByVal.

Using

Call validateAccount(validate)

would also work.

Thanks for the explanation. I've always defined my parameters using
the ByVal keyword when I need to protect the source variable.



--
Bob Quintal

PA is y I've altered my email address.
** Posted from http://www.teranews.com **
.



Relevant Pages

  • Re: Boolean variable not holding state
    ... you can only refer to that variable inside that routine. ... To declare a variable that can be used by all routines within the ... Even with Option Explicit the sub does not generate any error. ... implicitly defined variant validate in the function by treating it ...
    (microsoft.public.access.formscoding)
  • Re: Boolean variable not holding state
    ... you can only refer to that variable inside that routine. ... To declare a variable that can be used by all routines within the ... realized that your sub validateAccount knew nothing about the ... implicitly defined variant validate in the function by treating it ...
    (microsoft.public.access.formscoding)
  • Re: Paper - impossible to prove P=?NP
    ... Bryan did back up his statements. ... > not on the person trying to validate whether the claim is accurate. ... He can declare the proof being validated to be ... (leading to contradiction), or a definition not well-defined, etc. ...
    (sci.crypt)
  • Re: Boolean variable not holding state
    ... You've declared validate inside of btnSaveRecord_Click. ... only refer to that variable inside that routine. ... To declare a variable that can be used by all routines within the module, ... I have a form that calls another sub to validate text boxes. ...
    (microsoft.public.access.formscoding)
  • Re: validate XML with DTD and Xerces: Non-whitespace characters
    ... > as mentioned above I'd like to validate a simple XML-document with a ... If you want standalone validation with a DTD, ... The name you declare in the Document Type Declaration must be the ...
    (comp.text.xml)