Focus

P

Pam

Hi,

I have the following procedure set for the BeforeUpdate event for a text box
on a subform. Both referenced text boxes are on the subform.

Private Sub PriceQuote_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Analysis) Then
MsgBox "Please enter Analysis date!!"
Me.Analysis.SetFocus
End If
End Sub

It will give the msg as it should, but I get an error 2108 msg, "You must
save the field before you execute the GoToControl action, the GoToControl
method, or the SetFocus method."

The SetFocus line is highlighted in code. I haven't seen this before and
don't know how to correct it. Can someone please advise how to do so?

Thank you in advance,
Pam
 
P

Pam

Klatuu,

Thanks for the quick reply. I added the cancel code, but I'm still getting
the same message.

Pam
 
M

missinglinq via AccessMonster.com

This drove me nuts forever! You need to simply remove the line "Me.Analysis.
SetFocus." The "Cancel = True" automatically takes you back to the same text
box so that you're still in the Before_Update state, and the setfocus command
triggers the error again! Remove the setfocus line and it'll behave like you
want it to!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
P

Pam

Klatuu,

I didn't think there was a problem either. I've used this code, even
without the Cancel and it worked as it should. I don't understand the error
code stating I must "save the field".

Thanks,
Pam
 
P

Pam

Thanks for the reply. If I remove the SetFocus code, it won't take me back
to the text box that needs to be filled in (Analysis), before a date can be
put in next step (PriceQuote). I really would like for it to work this way
and it does in another database. I've checked and rechecked and can't find
the problem.

Thanks,
Pam
 
G

Guest

That is not the control that has the focus. Canceling the event of the
current control
(PriceQuote) will leave the cursor in that control, not the analysis control.

Actually, now that I think about it, the code is really in the wrong place.
It should be in the Before Update event of the analysis control. DOH!

Had I been paying attention, I could have answered it the first time.
 
P

Pam

I'm confused. I want the form set up so that if a user wants to put a date
in PriceQuote, BUT he hasn't filled in a date in Analysis first, I want the
message "Please enter Analysis date" and then the cursor to go from the
PriceQuote txt box to the Analysis txt box.

So, I thought it would go in the PriceQuote box and then the focus would
then go to the Analysis box.

Pam
 
M

missinglinq via AccessMonster.com

So you don't want your code in the Before_Update of PriceQuote, because that
would mean the user has already entered data there! You want the user
prevented from enetering anything in PriceQuote until there's a date in
Analysis. This should do the trick! As soon as the PriceQuote field is
entered Analysis is checked for a date. IsDate will make sure that a DATE has
been entered, whereas IsNull would just check to see if Analysis was empty.
With IsNull an entry that wasn't a date would still pass, so to speak.

Private Sub PriceQuote_GotFocus()
If Not IsDate(Me.Analysis.Value) Then
MsgBox "Please enter Analysis date"
Me.Analysis.SetFocus
End If
End Sub


I'm confused. I want the form set up so that if a user wants to put a date
in PriceQuote, BUT he hasn't filled in a date in Analysis first, I want the
message "Please enter Analysis date" and then the cursor to go from the
PriceQuote txt box to the Analysis txt box.

So, I thought it would go in the PriceQuote box and then the focus would
then go to the Analysis box.

Pam
That is not the control that has the focus. Canceling the event of the
current control
[quoted text clipped - 16 lines]

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
P

Pam

That did it!! It works just the way I wanted! Thank you so much for your
help!!

missinglinq via AccessMonster.com said:
So you don't want your code in the Before_Update of PriceQuote, because
that
would mean the user has already entered data there! You want the user
prevented from enetering anything in PriceQuote until there's a date in
Analysis. This should do the trick! As soon as the PriceQuote field is
entered Analysis is checked for a date. IsDate will make sure that a DATE
has
been entered, whereas IsNull would just check to see if Analysis was
empty.
With IsNull an entry that wasn't a date would still pass, so to speak.

Private Sub PriceQuote_GotFocus()
If Not IsDate(Me.Analysis.Value) Then
MsgBox "Please enter Analysis date"
Me.Analysis.SetFocus
End If
End Sub


I'm confused. I want the form set up so that if a user wants to put a
date
in PriceQuote, BUT he hasn't filled in a date in Analysis first, I want
the
message "Please enter Analysis date" and then the cursor to go from the
PriceQuote txt box to the Analysis txt box.

So, I thought it would go in the PriceQuote box and then the focus would
then go to the Analysis box.

Pam
That is not the control that has the focus. Canceling the event of the
current control
[quoted text clipped - 16 lines]
you
want it to!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top