UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> checking for required entry into a control on a form    
 
   
Nyteshade
post Feb 12 2007, 05:09 PM
Post #1

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



I have a form with a control that is text. I put the following in the beforeupdate event but is NEVER gets executed. When I debug it the value for' Me.unitID = Null' but the MsgBox doesn't get displayed! Is this a good way to check for required fields. If yes then can you see an error? If no is there a more better way? Thx all!

If Me.unitID = Null Or Me.unitID <= 0 Then
If MsgBox("UnitID is Required: <Yes> to try again; <No> to Exit.", vbYesNo) = vbNo Then
DoCmd.Close
Else
End If
Else
End If
Go to the top of the page
 
+
maxamis4
post Feb 12 2007, 05:11 PM
Post #2

UtterAccess Guru
Posts: 609



I would do this on the event On Form Load, or On Current. Try that
Go to the top of the page
 
+
Jack Cowley
post Feb 12 2007, 05:18 PM
Post #3

Retired Moderator
Posts: 37,716
From: The San Francisco Bay Area



Try this syntax:

If Len(Me.UnitID & vbNullString) = 0 Then
...rest of your code...
End if

Also, to check for null the syntax is:

If IsNull(Me.UnitID) Then

Not:

If Me.UnitID = Null

hth,
Jack
Go to the top of the page
 
+
Nyteshade
post Feb 12 2007, 05:22 PM
Post #4

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



Neither event you suggested will execute the code. All I am doing to get it to work is leaving the unitID blank and tabbing thru my form but the Msgbox never displays. It's so odd 'cause I have similar code the works just fine. Hmmmmmm.
Go to the top of the page
 
+
Nyteshade
post Feb 12 2007, 05:44 PM
Post #5

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



Copy that Jack... I'll bb when I test it out.
Go to the top of the page
 
+
Jack Cowley
post Feb 12 2007, 05:52 PM
Post #6

Retired Moderator
Posts: 37,716
From: The San Francisco Bay Area



Are you sure the Before Update event is not firing? Did you put a Stop in it to make sure? If you did and the Stop is never executed then you may have a corrupt form....

Jack
Go to the top of the page
 
+
Nyteshade
post Feb 13 2007, 10:00 AM
Post #7

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



Ok, the way I get the code to execute is to put it in the On LostFocus event of the control, it looks like:

If Len(Me.unitID & vbNullString) = 0 Then
If MsgBox("UnitID is Required: <Yes> to try again; <No> to Exit.", vbYesNo) = vbNo Then
DoCmd.Close
Else
' DoCmd.GoToControl Me.unitID
' me.unitID.SetFocus
End If
Else
End If

However, the two lines that are commented out (I've tried them both) NEVER move the cursor back to the unitID control! When I use the DoCmd action is bombs with some data mismatch error and when I place the cursor over me.unitID it says 'me.unitID = Null'. I didn't thing it was checking values, I just want to move the cursor back to the unitID control. Thx!
Go to the top of the page
 
+
Jack Cowley
post Feb 13 2007, 10:04 AM
Post #8

Retired Moderator
Posts: 37,716
From: The San Francisco Bay Area



Something is going on and I do not know what it is. The Before Update event should fire. Create a quick form using the Wizard and try your code in that form and see if it works.

If your current code is in the UnitID control then you can't set the focus to the control that has the focus. You have to set the focus somewhere else first:

Me.MyControl.SetFocus
Me.UnitID.SetFocus

Try the new form as this should not be this difficult...

I am outta here until about 1pm Pacific Time


Jack
Go to the top of the page
 
+
Nyteshade
post Feb 13 2007, 10:09 AM
Post #9

UtterAccess Ruler
Posts: 1,289
From: Ohio, USA



Copy that, I got the B4 to fire, thx... I'm outta here shortly after that, snow's getting deep here in cowtown ohio. Later...
Go to the top of the page
 
+
Jack Cowley
post Feb 13 2007, 10:12 AM
Post #10

Retired Moderator
Posts: 37,716
From: The San Francisco Bay Area



Glad to hear you got the Before Update to fire... Stay warm!

Jack
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 25th May 2013 - 05:58 PM