LostFocus ain't working...neither is OnExit

Randomblink

The Irreverent Reverend
Local time
Today, 12:25
Joined
Jul 23, 2001
Messages
279
Private Sub TARGET_LostFocus()
If Me.TARGET = "City" Then
PSRTYPE = "City"
Consultant_Selection.Visible = False
Design_Details__CITY_.Visible = True
Design_Details__CONTRACT_.Visible = False
Engineer_Data___Page.Visible = False
CTRCTM.Visible = True
ElseIf Me.TARGET = "Contract" Then
PSRTYPE = "Contract"
Consultant_Selection.Visible = True
Design_Details__CITY_.Visible = False
Design_Details__CONTRACT_.Visible = True
Engineer_Data___Page.Visible = True
CTRCTM.Visible = False
ElseIf IsEmpty(Me.TARGET) Then
Result = MsgBox("Please enter either City or Contract to move on please", vbOKOnly, "Entry is Required") = vbOK
Me.TARGET.SetFocus
End If
End Sub

This is the code...(don't tell me there is an easier way, Im not familiar enough with VB to get there). I want the STUPID STUPID combo box to check itself. If it has CITY as an Entry, I want it to invisible certain fields. If it is Contract as an Entry, I want it to invisible other fields. And...

...and here is where I am mystified...

If...it is null, empty, not filled in, blank, whatever else can mean NOT FILLED IN...

I want it to open a message box...wait for the user to hit OK...then set the focus right back on itself...

I have done this THOUSANDS (literally) of times with Access97. I have not tried it yet with Access 2000...at least not that it works. Im gonna include background on the fields real quick in case it would help.

TARGET - combo box
PSRTYPE - Project Type (either City or Contract)
Consultant_Selection - Is a page on a tab box
Design_Details_City - same as above
Design_Details_Contract - also same
Engineer_Data___Page - same same still
CTRCM - Textbox on a page in the tab box

PLEASE HELP! Im doing this database for the city...and hopefully some serious 'thank you's' and just want to get the little details worked out...argh!

I can't believe how hard this one thing is...I have done this many many times before...never had a problem...
 
You have two basic problems.
1. To check for Null use: If IsNull([YourControlName])
2. To get the focus back to the control you would need to set the focus first to any other control then back to the control that you just left.

But I would do this completely different. I would validate the entry BEFORE the data actually is saved in the table by using the "Before Update" event of the control. Below is an example of how this can be done using a Case Select statement instead of all those If statements. Being the event is Canceled when the control is Null, the focus remains in the control. No need to have to set it back to the control.

' ***************** Begin Code ******************
Private Sub Target_BeforeUpdate(Cancel As Integer)
Dim strMsg As String, strTitle As String
strMsg = "Please enter either City or Contract to move on please"
strTitle = " Entry is Required"

Select Case Me.Target
Case "City"
Me.Consultant_Selection.Visible = False
Me.Design_Details__CITY_.Visible = True
Me.Design_Details__CONTRACT_.Visible = False
Me.Engineer_Data___Page.Visible = False
Case "Contract"
Me.Consultant_Selection.Visible = True
Me.Design_Details__CITY_.Visible = False
Me.Design_Details__CONTRACT_.Visible = True
Me.Engineer_Data___Page.Visible = True
Me.CTRCTM.Visible = False
Case Else
MsgBox strMsg, vbExclamation + vbOKOnly, strTitle
Cancel = True
End Select
End Sub
' ****************** End Code *******************

PS: Not real sure about the names of your controls in the code above. I used the names from your code example. All of the "_" (underscores) at the end of the names on some of the controls have me wondering. If they are not correct, change them to make the example work.

HTH
RDH

[This message has been edited by R. Hicks (edited 08-10-2001).]
 
Thank you much.
I have never dealt with Select Case before.
The only VB I have dealt with is whatever I piecemeal together from code in the help pages. I am fairly comfortable with quite abit, but missing many pieces to a solid VB knowledge.
Thanks again...
I have to wait to get this laptop removed and replaced with it's replacement before I can test out the code, but I appreciate the help...
 
I have one question on the Select Case direction you took...

What is with the Cancel = True and the beginning of the sub where you wrote it like...
Private Sub Target_BeforeUpdate(Cancel As Integer)

What does that do? I'm trying desperately to learn and would truly appreciate it if you could help. Thanks...
 
The Cancel is built into the BeforeUpdate of any control that can use BeforeUpdate. If you set Cancel = True, it will stop the control from saving the information in your table. This is where I usually put the majority of my validation rules.

Keagan Quilty
Kilbride, Newfoundland
 
Thank you very much...
I have to say I have learned more from this list than from anything I have ever accessed...
 

Users who are viewing this thread

Back
Top Bottom