Userform

Please can you help with the attached

On the userform I want to amend the code so that the spinbutton1 alters the date by +1 (Add/Subtract) in textbox1

 Book1.xls
Kiwi-123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

[ fanpages ]IT Services ConsultantCommented:
Add two event subroutines like this...

Private Sub SpinButton1_SpinUp()

  If IsDate(TextBox1.Text) Then
     TextBox1.Text = Format$(DateAdd("d", 1, CDate(TextBox1.Text)))
  End If
     
End Sub
Private Sub SpinButton1_SpinDown()

  If IsDate(TextBox1.Text) Then
     TextBox1.Text = Format$(DateAdd("d", -1, CDate(TextBox1.Text)))
  End If

End Sub

' --- rest of your existing code ---

BFN,

fp.
Private Sub SpinButton1_SpinUp()

  If IsDate(TextBox1.Text) Then
     TextBox1.Text = Format$(DateAdd("d", 1, CDate(TextBox1.Text)))
  End If
     
End Sub
Private Sub SpinButton1_SpinDown()

  If IsDate(TextBox1.Text) Then
     TextBox1.Text = Format$(DateAdd("d", -1, CDate(TextBox1.Text)))
  End If

End Sub

Open in new window

0
[ fanpages ]IT Services ConsultantCommented:
For example, see attached...
Book1-Updated.xls
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kiwi-123Author Commented:
Thanks Fanpages, I just need to tweak at the code so that:-

TextBox2.SetFocus

Is performed after the Spinbutton click. My code works if I press the spin button twice, but not if just once?

Private Sub SpinButton1_SpinUp()

  If IsDate(TextBox1.Text) Then
     TextBox1.Text = Format$(DateAdd("d", 1, CDate(TextBox1.Text)))
     TextBox2.SetFocus
  End If
     
End Sub
0
[ fanpages ]IT Services ConsultantCommented:
Hi,

Try placing a 'DoEvents' call in between the two lines, thus:

Private Sub SpinButton1_SpinUp()

  If IsDate(TextBox1.Text) Then
     TextBox1.Text = Format$(DateAdd("d", 1, CDate(TextBox1.Text)))
     DoEvents
     TextBox2.SetFocus
  End If
     
End Sub

BFN,

fp.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.