DateAdd user inputs the date
DateAdd(DateInterval.Hour, -9, #_ _ :_ _ :_ _ #)
i want to use the DateAdd function but instead of adding to a specified time, i want the user to input a time(with a text box)
i am fairly new to this so the solution is probably obvious.
if you are curious im doing a time zone program(to work out the time in a different time zone)
Re: DateAdd user inputs the date
Welcome to the forums. :wave:
You have stated what you want, but, what is the question?
Re: DateAdd user inputs the date
instead of adding to a specified time how do i use one the user has entered into a textbox (im doing this for school and my teacher isnt good at explaining)
Re: DateAdd user inputs the date
You mean this?
Code:
Private Sub Command1_Click()
Text2.Text = DateAdd("h", Text1.Text, Time)
End Sub
Re: DateAdd user inputs the date
also ive used a random time to add to(instead of what the user enters), just to see if it works, but its saying compile error:range has no values when i Dim DateAdd(dateInterval.Hour, -9, #9:00:00 PM#)(if thats what im supposed to do):eek2:
any suggestions? am i on the right track?
Re: DateAdd user inputs the date
the user doesnt enter wat they want added to the time, but wat time the hour/s will be added to. they enter the time themselves from which the program will add -9 hours and display the result.
Re: DateAdd user inputs the date
Quote:
Originally Posted by
Charlie94
but wat time the hour/s will be added to. they enter the time themselves from which the program will add -9 hours and display the result.
Ok...so just move the text1.text line to the end instead of in the middle.
Re: DateAdd user inputs the date
tried that
here is the relevent code:can u tell me whats wrong, why and how to fix it
Code:
Dim dteTime As Date
Private Sub cmdTimeDifference_Click()
lblItaly(CbDate) = DateAdd("h", -9, txtHours)
End Sub
Private Sub Form_Load()
txtHours(CbDate) = dteTime
End Sub
I get 'runtime error 450'
Re: DateAdd user inputs the date
What is the verbage for the error and what line gets highlighted when it happens?
Re: DateAdd user inputs the date
wrong number of arguments or invalid property assignment
lblItaly(CbDate) = DateAdd("h", -9, txtHours) gets highlighted
Re: DateAdd user inputs the date
Yeah, I had feeling it was going to be that line, and the wrong number of arguments is coming from thisFirst, is lblItaly in a label array?
Second, if it is, then it is expecting a number, not a built in VB function.
Re: DateAdd user inputs the date
yes to the array, dont know about the second one, i just added (CbDate) cause it stopped another error
Re: DateAdd user inputs the date
also instead of just the time ill use the date too(so if the user enters 1 am it will go back to the previous date)
Re: DateAdd user inputs the date
wait sorry no its not in an array, ive had errors involving arrays though
Re: DateAdd user inputs the date
1) If you use dateadd and it goes back to the previous day then you need to format it to just grab the time.
For example
Code:
Format(DateAdd("h", -9, Time), "hh:mm:ss")
Quote:
blItaly(CbDate) = DateAdd("h", -9, txtHours) gets highlighted
2) What is the value of "txtHours" and what is the value of "CbDate"
Re: DateAdd user inputs the date
i just added (CbDate) cause it stopped another error
Private Sub Form_Load()
txtHours(CbDate) = dteTime
End Sub
i put that there so they edit the 12:00:00 AM to their time
Re: DateAdd user inputs the date
Quote:
i just added (CbDate) cause it stopped another error
You just cannot add anything to anything to stop errors :)
What Hack initially suggested and I re-emphasized in post 15 is that you need to use it like this
Code:
Format(DateAdd("h", -9, Time), "hh:mm:ss")
If you want to store it in a label then do this
Code:
Label1.Caption = Format(DateAdd("h", -9, Time), "hh:mm:ss")
If you want the user to enter the time then do this
Code:
Label1.Caption = Format(DateAdd("h", -9, TxtHours), "hh:mm:ss")
Ensure that the value of TxtHours is a valid timevalue. For example, the textbox should have a value of 00:00:00 (in the format of hh:mm:ss)
Re: DateAdd user inputs the date
okay but what if i wanted the user to enter the day of the week and the time. i believe the code is
"dddd hh:mm am/pm" (not sure abot the am/pm though)
i want it so the user enters the day and time in that format and then the label shows it in that format