Year(date) 
Author Message
 Year(date)

Hi
I want to get a textbox to display a Year(Date) and scroll up(+) or down(-)
by input from another textbox. i have created a test form to work out
how to do this(code below) problem when I switch from plus to minus I
get an incorrect answer, what am I doing wrong please?

Option Explicit
Dim xYes As Boolean
Dim iX As Integer

Private Sub Command1_Click()

If Option2.Value = True Then
  txthold = Year(Date) + txtImp + iX
  Option2.Value = False
  If xYes = True Then iX = iX + txtImp
  xYes = False
  Text1.Text = iX 'used to see what No. is reached
ElseIf Option1.Value = True Then
  txthold = Year(Date) - txtImp - iX
  Option1.Value = False
  If xYes = True Then iX = iX + txtImp
  xYes = False
  Text1.Text = iX
End If

End Sub

Private Sub Form_Load()
txthold = Year(Date)
txtImp = 1
End Sub

Private Sub Option1_Click()
xYes = True
End Sub

Private Sub Option2_Click()
xYes = True
End Sub

Ron



Fri, 28 Oct 2011 23:44:01 GMT  
 Year(date)
One possibility is that in you calculation in the command
button click event is starting off from the current year,
not from the year that was last calculated and is now in
the txtHold textbox.

So, if I select minus, click on button the txtHold textbox
will get 2008.

Now if I change to the + plus option and click again I am
adding 1 from the txtImp textbox and from the iX variable
so now that becomes 2009 _ 1 + 1 and you get 2011

If what yo are after if to be able to increment or decrement
a number in a textbox by clicking a button, the UpDown
control that is in the Microsoft Windows Common Controls-2
might be of use to you,

Also, a suggestion, when accessing the data in the Tex property
of the textbox is is a good idea to use the full name of the property:

txtImp.Text   isntead of just txtImp

Regards, Saga


Quote:
> Hi
> I want to get a textbox to display a Year(Date) and scroll up(+) or
> down(-)
> by input from another textbox. i have created a test form to work out
> how to do this(code below) problem when I switch from plus to minus I
> get an incorrect answer, what am I doing wrong please?

> Option Explicit
> Dim xYes As Boolean
> Dim iX As Integer

> Private Sub Command1_Click()

> If Option2.Value = True Then
>  txthold = Year(Date) + txtImp + iX
>  Option2.Value = False
>  If xYes = True Then iX = iX + txtImp
>  xYes = False
>  Text1.Text = iX 'used to see what No. is reached
> ElseIf Option1.Value = True Then
>  txthold = Year(Date) - txtImp - iX
>  Option1.Value = False
>  If xYes = True Then iX = iX + txtImp
>  xYes = False
>  Text1.Text = iX
> End If

> End Sub

> Private Sub Form_Load()
> txthold = Year(Date)
> txtImp = 1
> End Sub

> Private Sub Option1_Click()
> xYes = True
> End Sub

> Private Sub Option2_Click()
> xYes = True
> End Sub

> Ron



Sat, 29 Oct 2011 00:49:12 GMT  
 Year(date)
Why not use UpDown control, or DTPicker control? They are part of "Microsoft
Windows Common Controls-2 6.0".


Sat, 29 Oct 2011 01:44:43 GMT  
 Year(date)
Hi Nobody and Saga
Thanks for your posts, solved the problem now by using the value of
txtHold.Text works fine.

Ron

Quote:

> Why not use UpDown control, or DTPicker control? They are part of "Microsoft
> Windows Common Controls-2 6.0".



Sat, 29 Oct 2011 21:28:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Year(Date) produces a Type Mismatch

2. Fiscal Year Dates

3. Newbie: Need help with setting Fiscal Year Date Range

4. Newbie: Need help with setting Fiscal Year Date Range

5. Fiscal Year Date Formula?

6. last year and year to date

7. difference between two dates ,in years,months,and days

8. In which quarter is [date] of fiscal year?

9. Convert weeknumber and year into a date

10. TransferSpreadsheet is always out 4 years and 1 day on date import

11. Week of year to actual dates

12. Year 2000 Date Windowing

 

 
Powered by phpBB® Forum Software