Adding to a Access Form in VBA

lg5050

Registered User.
Local time
Today, 04:05
Joined
Nov 26, 2014
Messages
25
i have a form in access 2010 and i have a text box called USLINE and other one called USOFlag and i want the USLINE field to do like if it's is not null then it is a Y else N i try to do it in the LostFocus function but i cant get it to work Please help me on this!!!!!:confused:

Here is the the code that i used:

Private Sub USLine9_LostFocus()

If IsNull(USLine9.Value) Then
USOFlag.Value = "Y"
Else
USOFlag.Value = "N"
End If

End Sub
 

Attachments

  • access form1.png
    access form1.png
    72.3 KB · Views: 110
Try this. I think the problem is the .value, but in any case, this always works for me.
Code:
Private Sub USLine9_LostFocus()
If IsNull(USLine9) Or USLine9 = "" Then
USOFlag = "Y"
Else: USOFlag = "N"
End If

End Sub
 
No i try that and it did the same thing. It did nothing. I'm putting it in the LostFocus event is that right???
 
No i try that and it did the same thing. It did nothing. I'm putting it in the LostFocus event is that right???

It works for me, here's my test sample;

Code:
Private Sub Text6_LostFocus()
    If Text6 & "" = "" Then
        Me.Text8 = "N"
    Else
        Me.Text8 = "Y"
    End If
End Sub

For the LostFocus event to occur you must at least enter the control. If you never enter the control then the LostFocus event will not trigger.

If this is the case, you could consider the Form's OnCurrent event.
 
Here is the database i tryed it and it don't work. Is there something i doing wrong.
 

Attachments

Here is the database i tryed it and it don't work. Is there something i doing wrong.

Yes, it does work. I'm not sure what you could be doing wrong but it certainly works.
 
Your input mask was causing the problem. I am not smart enough to know why, but when I cleared the input mask for the field, it worked perfectly.
 
Your input mask was causing the problem. I am not smart enough to know why, but when I cleared the input mask for the field, it worked perfectly.

I noticed the input mask, ignored it, tested in and out of the control with various values and it worked as intended. I did not alter anything.

Steve.
 
You are right. I tried it on my sample with an input mask and it worked OK. Guess it was just one of the mysteries of Access, of which I have more than my share.
Glad to hear that it is now working.
 
You are right. I tried it on my sample with an input mask and it worked OK. Guess it was just one of the mysteries of Access, of which I have more than my share.
Glad to hear that it is now working.

I'm more curious now as to why it wasn't working for the OP.
 
Yeah i notice it too and i got it to work perfectly. Thanks a lot.
 
The important thing to remember is that you have to check for a Null value or a zero length string each time. That is why you have the following. This has been pointed out to me many times on this forum that it is almost routine for me.

If IsNull(USLine9) Or USLine9 = ""
 

Users who are viewing this thread

Back
Top Bottom