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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox troubles 1

Status
Not open for further replies.

Tailgun

Technical User
Mar 30, 2002
417
US
To simplify it I have a form with a checkbox and textbox.
When the user clicks the check box the current date is inserted into the textbox.

Private Sub Check1_Click()
txtS1openDate.Text = Date
End Sub

both the checkbox = true and the date in the textbox are saved to a SQL database. So far so good :) but when the user opens the form a few days later for some reason the new current date is inserted into the textbox without clicking the checkbox which of course already has a check in it. I need it to retain the original date stored in the database.

To add to the confusion I have another form doing a similiar thing and it works fine.

I sure hope someone has some suggestions.

Thanks for any and all help :)
 
Is it a timing thing? Could the date be going into the textbox before the checkbox is set to being checked?
 
I guess that's possible since a similiar code works on another form but I'm not sure at all how to solve it.

thanks for the response
 
When does the date get moved from the database to the check box? Maybe you could set the checkbox first and then move the date?

Sorry if this I'm missing the point with this...

 
When the user opens that form a recordset loads the information into all the textboxes checkboxes etc from the database. For some unknown reason it refreshes the date in the txtbox to the current date. Even though I have it set for that to change only with a click event in the checkbox.
 
Maybe i'm totally wrong with this because i dont know much about sql but the click on the checkbox makes txtS1openDate.Text "date" and not for example 10-9-2002 maybe this is the problem, or i could be complety wrong you could always give it a try..

Tell me if it made any sense [afro]

Greets,

Thavolt
 
The strange problem is that it does work on another form in my application with about the same situation. ie a checkbox and textbox stored in SQL then recalled when the form is reopened but the results are ok on one form and not the other.
 
A few days later, when you pull the form back back, the checkbox is being set with the checked value. When the checkbox is set, the click event is fired. Whenever a check box value is set programmatically, the click event is going to fire, and you have to program for that. What I've done in the past is something like the following:

Private Sub Check1_Click()
If (fBol_HandleClick = True) Then
txtS1openDate.Text = Date
End If
End Sub

then in the code

fBol_HandleClick = False
Check1.Value = vbChecked
fBol_HandleClick = True


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks a million Cajun that sure solved the problem. :):)
 
Cajun,

I just noticed something when using your solution. Sorry I'm so late getting back I was out of town. Your solution works fine in that it keeps the check and old date intact when the form is reopened later but it somehow now won't put the current date in the txtbox when the chkbox is clicked on a record containing a new form.

Any suggestions ?
Thanks again for all your help on this
 
Make sure that fBol_HandleClick is initialized to True in the FormLoad. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Here is what is in my formload event there is a bit of other code that isn't affected by the problem.

fBol_HandleClick = False
Check1.Value = vbChecked
Check5.Value = vbChecked
fBol_HandleClick = True
 
That code will set both checkboxes, and the code inside of the click event conditional will NOT be executed.

If its a new record, and you want to the click code to be executed, then do not set the handleclick to false before setting the checkbox value. If you want to use to check the box, then do nothing.

Only set the variable to false when you want the checkbox code to be bypassed. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top