OnChange event gives Null Error

NigelShaw

Registered User.
Local time
Today, 06:23
Joined
Jan 11, 2008
Messages
1,575
Hi,

i am trying to routine that checks text while you type however, all i get is an error saying Invalid use of Null'

i am using the OnChange event

here is a snippet
Code:
If Len(Me.MyTextbox.Value) = 0 Then
Zap = Nz(CheckMyText(Me.MyTextbox.Value), 0)
Select Case ZAP
Case 2
DoSomeCode
Case 8
DoSomeOtherCode
End Select

my thought was that as soon as you add text into the textbox, there wouldnt be a Null so why do i get the error?

i added a button with the same calling code and it works just fine so the routine itself is ok. Its the updating while typing that doesnt work.

i also tried this yesterday on my TreeView where i wanted to type a name into a textbox and have the tree update while i type but i got the same message


cheers

Nigel
 
It's because you are using the .VALUE instead of .TEXT. In this case you must use .Text because the value has not yet changed until the typing is totally done and you've either hit enter or exited from the control.
 
Hi Bob,

still an error though '94 Invalid use of Null'

what i am actually doing is trying to create a form that visually displays if your password is strong enough. When i remove the OnChange event and use a button, it checks it just fine but its a one off hit and i wanted a running visual method that changes as the password gets stronger.

currently by using the button i get

Code:
Weak
lblWeak.caption = Weak
lblMed.Visible = False
lblStng.Visible = False

Medium
lblWeak.Visible = False
lblMed.Visible = True
lblMed.Caption = Medium
lblStng.Visible = False

Strong
lblWeak.Visible = False
lblMed.Visible = False
lblStng.Visible = True
lblStng.Caption = Strong

these are all in a select case statement. The whole thing works and returns a good result pending the password strength but its just gettnig it to work while updating the textbox.

Any ideas?

N
 
Post the entire On Change event you are using right now.
 
Hi Bob,

code:
Code:
Private Sub Password_Change()
On Error GoTo ErrorHandler

    Dim strength As Long
    Dim red As Long
    Dim yellow As Long
    Dim green As Long
    Dim varPw As Variant

    varPw = Me.password.Text

    red = RGB(255, 0, 0)
    yellow = RGB(255, 255, 0)
    green = RGB(0, 255, 0)

    If IsNull(varPw) = True Then
        ' visibility
        weak.Visible = False
        medium.Visible = False
        strong.Visible = False
    
        GoTo ProgramExit
    End If

    ' check password
    strength = Nz(PasswordStrengthCheck(Me.password.Value), 0)

    Select Case strength
    Case 0 To 2  ' weak

        ' only weak visible, red backcolor w/ black text

        With weak
            .Visible = True
            .BackColor = red
            .ForeColor = -2147483630
        End With

        medium.Visible = False
        strong.Visible = False

    Case 3  ' medium

        ' weak and med visible, both yellow, but only medium text visible

        With weak
            .Visible = True
            .BackColor = yellow
            .ForeColor = yellow
        End With

        With medium
            .Visible = True
            .BackColor = yellow
            .ForeColor = -2147483630
        End With

        strong.Visible = False

    Case Is >= 4  ' strong

        ' all visible, all green backcolor, but only strong label forecolor visible

        With weak
            .Visible = True
            .BackColor = green
            .ForeColor = green
        End With

        With medium
            .Visible = True
            .BackColor = green
            .ForeColor = green
        End With

        With strong
            .Visible = True
            .BackColor = green
            .ForeColor = -2147483630
        End With

    End Select

ProgramExit:
    Exit Sub
ErrorHandler:
    MsgBox Err.Number & " - " & Err.Description
    Resume ProgramExit
  
End Sub

cheers

N
 
Two things:

1. You still have .Value in there:
strength = Nz(PasswordStrengthCheck(Me.password.Value), 0)

it NEEDS to be

strength = Nz(PasswordStrengthCheck(Me.password.Text), 0)


Also, I would not have a control/field/object named password as that is an Access Reserved Word.
 
Hi Bob

thanks for the help, works a treat now :)

cheers

N
 

Users who are viewing this thread

Back
Top Bottom