Removing Text From Control (1 Viewer)

Endojoe

Registered User.
Local time
Today, 05:20
Joined
Apr 7, 2009
Messages
20
I have a form in which I need to auto-populate a couple of controls when data entry begins in certain controls. I have achieved this using the following:

Code:
Private Sub PART1_Dirty(Cancel As Integer)

If Me.Cert_Type = 1 Then
    Me.ITEM1 = "1"
    Me.SER1 = "N/A"
ElseIf Me.Cert_Type = 2 Then
    Me.ITEM1 = "1"
    Me.SER1 = SPU_LOT_NUMBER
ElseIf Me.PART1 = Null Then
    Me.ITEM1 = Null
    Me.SER1 = Null

End If

End Sub

However...the last ElseIf will not clear the controls. I would like the auto-populated controls to clear themselves if the user mistakenly enters data then deletes it. I have tried using the above code in the 'on change' and 'on Key Press' events also, to no avail. I'm either mis-using Null somehow, I need to use a different event trigger, or perhaps split the statement between two event triggers, I've tried numerous variations of all the above with no luck. Any suggestions?

Thanks In Advance :)

-Will-
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:20
Joined
Aug 30, 2003
Messages
36,118
Nothing is ever "equal" to Null, as Null represents an unknown. Try

ElseIf IsNull(Me.PART1) Then
 

Endojoe

Registered User.
Local time
Today, 05:20
Joined
Apr 7, 2009
Messages
20
Much thanks once again for setting me on the right track. It worked beautifully! I ended up using the 'on change' to trigger the auto-populate and have been experimenting with different triggers to clear the controls, but when using KeyDown and KeyPress, the controls don't clear out until the backspace key is pressed one more additional time after all data has been erased, however...using KeyUp the auto-populate happens but is immediately removed with each key stroke, which has me quite puzzled. Ideally I would like the controls to clear on the release of the backspace key following deletion of the last character, rather than require an additional key stroke. Key up would seem to be the place for this to happen, but it doesn't seem to be playing well with my other statement in 'on change'. It acts as though every keystroke finds the control 'null' and thus erases the other two controls...I am at a loss to explain this behavior. Perhaps I still do not fully grasp the Null meaning? Because it would seem that using the KeyDown and KeyPress triggers should reflect similar results as the KeyUp, just at slightly different times. What am I missing?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:20
Joined
Aug 30, 2003
Messages
36,118
If you use the change event, you have to use the .Text property of that control, as the default .Value property is not updated yet. That's probably also true of the key events. Personally I typically use the after update event for stuff like this, as I just wait for the user to finish.
 

Users who are viewing this thread

Top Bottom