Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Date and Time when option button is selected 1

Status
Not open for further replies.
Jun 2, 2004
66
US
I have an option button set up called "complete". When users select this option, I would like the current date and time to appear in a box below. Please help with the code.

Thanks
 
Text1.Text = Now

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
What you gave me looks like a Default Value.
Would this be incorporated into an if statement somehow, or could I attach this to an event procedure? I would like the current date and time to appear if the user selects the completed option button?
 
Double-click on the option button. Paste the code johnwm gave you into the event. The only thing you might have to change is "Text1", which you should replace with the name of the textbox you want the current time to appear in.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
chiph. Thanks for the tip. Here is what I used.


Private Sub Completed_Click()
Text1.Text = Now
End Sub

Text1 is the name of my text box. However, when I click on the option button I get the following error.

Run-time error 2185
You can't reference a property or method for a control unless the control has the focus

What am I doing wrong?

Thanks
 
do you use some other method of "Completed" ?
 
I have two option buttons; In Progress and Completed. When the user clicks on Completed, I want the current date and time to appear in the text box below (called Date/Time Completed) In addition, if the user selects the In Progress button after selecting Completed, I would like the date and time to disappear until Completed is selected again.

Thanks
 
Sorry fheyn. The answer to your question is no. I do not use another method of "completed
 
To test the code start a new project and add 2 option buttons and a textbox. Name the options InProgress and Completed. Leave textbox as text1. Copy this code and run it.

Private Sub Completed_Click()
Text1.Text = Now
End Sub

Private Sub InProgress_Click()
Text1.Text = ""
End Sub

This works as you say you want it to. If you are getting an error in your other app using this code then there is a conflict somewhere with the control(s) named Completed. If you can't figure it out post more of your code so we can see what else is going on that could cause the error as the code above alone will not cause it. Hope this helps.
 
bmdb. Thanks for your response. I did exactly as you said with starting a new project, but it didn't even work in the new project. Since it worked for you, I can assume that I am definitely doing something wrong here.

I created a new form and added 2 option buttons and a textbox with the names you have listed above. I then placed this code in the On Click of the Completed option button. When I try to run it, I am getting the same run time error as mentioned in my previous replies. Please tell me what I am doing wrong here.

Thanks much!!
 
The code I supplied is the click event for both option buttons. Don't paste the code in the click event paste the code in the empty IDE as is. The only code you should see in the IDE is what I have above and maybe Option Explicit at the very top.
 
ineedyourhelp

can you confirm your version of Visual Studio?

Or
are you using Access?

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
First, meyber you might hasve got a quicker and more accurate answer by posting one of the access forums.

It appears that your error is a "party piece" of access. i.e. that it will not allow you to set the properties of a control withou it having the focus.

follow this url Access rants

fortunatley the answer is
instead of

text1.text = now
try
text1.value = now

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
bmdb,
The only code that is visible is the code that you supplied. When I look at the On Click (double clicking on option buttons in design view) for both options, they both contain (Event Procedure) When I click on the ... button next to (Event Procedure) it takes me to the code.

I am still getting the same error.

Thanks
 
Matt.

Thanks so much. Your tip worked like a charm!!!

Thanks also to everyone else who chipped in.

Much appreciated.
 
My Pleasure

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top