Select control on a form after calling procedure

G

Guest

I have a form that allows users to enter working days for a month in 12 text
boxes and I call a ValidateWorkingDays procedure in the BeforeUpdate event
for each monthly text box. If user needs to re-enter value I have this code
in my ValidateWorkingDays procedure:
With Me.Days
.SetFocus
.SelStart = 0
.SelLength = Len(Days)
End With
Days is a string in the ValidateWorkingDays procedure and I pass the
textbox control text to the procedure e.g. Call
ValidateWorkingDays(txtApril.Text, cancel = False)

I get invalid use of Me keyword in a runtime error.
I don't want to repeat code in each month. I'm new at this thanks for any
help.
Jake
 
B

Bob Phillips

Is Days the argument in the ValidateWorkingDays procedure? If so, Me is not
needed as it should be used in the call

With Days
.SetFocus
.SelStart = 0
.SelLength = Len(Days.Text)
End With

and

ValidateWorkingDays(Me.txtApril.Text, cancel = False)


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

I see what you mean. But I get a runtime error now:
"With object must be user-defined type, object or variant"
Is this because I declared Days as a string in my procedure:
Public Sub ValidateWorkingDays(Days As String, Cancel As Boolean)
thanks!
 
B

Bob Phillips

Yes that would give an error it should be

Public Sub ValidateWorkingDays(Days As Object, Cancel As Boolean)

or

Public Sub ValidateWorkingDays(Days As MSForms.TextBox, Cancel As Boolean)



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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