I have a program which is scheduled to run twice a day. The user selects the day of the week from a combo box, then selects what times they would like the program to start and what time they would like it to stop.
They have two start times and two stop times per day. For example, you can start the program at midnight, stop it at 6am, then start it up again at 8pm and run it until the day ends (11:59pm).
The days and times are stored in a simple MS Access table. When the user selects a day from the combo box, the CWNumEdit boxes load with the values from the database.
My problem is that when the user selects a day, it will load the CWNumEdit boxes with the values from the database, but only the first time... After I select another day, it keeps the previous values and does not change the values to the values within the database.
Here's some code:
Private Sub cboDay_Click()
Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\dates.mdb")
Set rs = db.OpenRecordset("Schedule")
blnLoadStatus = False
While Not rs.EOF
If cboDay.Text = rs!Day Then
CWNumEdit1.Value = rs!OnTime_1
CWNumEdit2.Value = rs!offtime_1
CWNumEdit3.Value = rs!ontime_2
CWNumEdit4.Value = rs!offtime_2
blnLoadStatus = True
rs.Close
Exit Sub
Else
rs.MoveNext
End If
Wend
End Sub
'then when the value is changed, it goes here:
Private Sub CWNumEdit1_ValueChanged(Value As Variant, PreviousValue As Variant, ByVal OutOfRange As Boolean)
If blnLoadStatus = True Then
Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\dates.mdb")
Set rs = db.OpenRecordset("Schedule")
While Not rs.EOF
rs.Edit
If rs!Day = cboDay.Text Then
rs!OnTime_1 = CWNumEdit1.Value
rs.Update
End If
rs.MoveNext
Wend
Else
End If
End Sub
...and so on for onTime_2, offTime_1, and offTime_2. The problem is that after the first time I select a day from the combo box, it goes to the Private Sub CWNumEdit1_ValueChanged, then the same for CWNumEdit2, but the program does not jump to CWNumEdit3_ValueChanged,or CWNumEdit4_ValueChanged.
This does work the first time, but the second time you change the combo box day, it does not recognize that the values are being changed.
Please Help!