Setfocus problem

A

aMack

On the Field [Customer Invoice Date] - I have the following code on a form

Private Sub Text35_Change()
If (Me.Ready_to_Bill) = No Then
MsgBox "Cannot Invoice if READY TO BILL is not Selected"
Cancel = True
Me.[Customer Invoice Date].Value = Null
Me.[Customer Invoice number].SetFocus
End If
End Sub

No matter what I do the Setfocus gives me an error. I tried changing the
Setfocus to a simpler named field but no change.

Could it be that the field [Customer Invoice Date] is a date field?
 
K

Klatuu

When asking a question about an error, post the error and on which line the
error occurs.

The first thing I see is you are using the Change event. I think you want
the After Update event. The Change event does exactly what it name says. It
fires on every change. That means if fires for every kestroke you enter in
the control.

I would suggest a different method. Make your text box disabled and enable
it in the after udate event of ready to bill.
 
D

Dale Fye

First off, the Cancel statement is not going to do anything in this context,
since the Change event doesn't have a cancel parameter associated with it.

I would assume that [Customer Invoice Date] would have a date/time datatype,
which can accept NULL values if the fields Required property is set to No
(false).

As far as the set focus is concerned, what error are you getting? Are you
sure you have a control named [Customer Invoice number]? Personally, I like
to give my controls names that are different from their control source and
prefix the control name with the type of control (txt_ , cbo_ , lst_ , ...),
and replace all spaces with underscores (this way I don't have to wrap
everything in square brackets[]), so that when I want to refer to a control,
I know that it will look something like:

me.txt_Cust_Inv_Num

HTH
Dale
 
A

aMack

Thanks for the response:

The error message is" Object does not support this prpoerty or method"

This Code works on a differeent field on the same form. [Customer Invoice
Number]
 
A

aMack

Removed the "Cancel" line and moved the code to On Enter - Got the results I
was looking for.

Thanks to all.
--
A MACKENZIE, CMA, MBA


Marshall Barton said:
aMack said:
On the Field [Customer Invoice Date] - I have the following code on a form

Private Sub Text35_Change()
If (Me.Ready_to_Bill) = No Then
MsgBox "Cannot Invoice if READY TO BILL is not Selected"
Cancel = True
Me.[Customer Invoice Date].Value = Null
Me.[Customer Invoice number].SetFocus
End If
End Sub

No matter what I do the Setfocus gives me an error. I tried changing the
Setfocus to a simpler named field but no change.

Could it be that the field [Customer Invoice Date] is a date field?

You have several other problems before you can worry about
setfocus.

First, the Change event is the wrong event for what you are
trying to do. I suspect that the AfterUpdate event would be
more appropriate.

Second, if you would have used the OPTION EXPLICIT statement
at the top of the module, you would have received compile
errors on the use of the undeclared variables No and Cancel.

I think you should be using False instead of No.

The Cancel line has no effect in the Change (and
AfterUpdate) event (perhaps Me.Text35.Undo??)
 
M

Marshall Barton

aMack said:
On the Field [Customer Invoice Date] - I have the following code on a form

Private Sub Text35_Change()
If (Me.Ready_to_Bill) = No Then
MsgBox "Cannot Invoice if READY TO BILL is not Selected"
Cancel = True
Me.[Customer Invoice Date].Value = Null
Me.[Customer Invoice number].SetFocus
End If
End Sub

No matter what I do the Setfocus gives me an error. I tried changing the
Setfocus to a simpler named field but no change.

Could it be that the field [Customer Invoice Date] is a date field?

You have several other problems before you can worry about
setfocus.

First, the Change event is the wrong event for what you are
trying to do. I suspect that the AfterUpdate event would be
more appropriate.

Second, if you would have used the OPTION EXPLICIT statement
at the top of the module, you would have received compile
errors on the use of the undeclared variables No and Cancel.

I think you should be using False instead of No.

The Cancel line has no effect in the Change (and
AfterUpdate) event (perhaps Me.Text35.Undo??)
 

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