Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

CWNumEdit and Databasing in Visual Basic

I have a schedule program written that will determine what days and hours a program will run. This information is stored in a simple table which just has a few columns: Day, OnTime, and OffTime. The user can edit the schedule by selecting the day from a combo box and using a Number Editing box. This does work but not the way I want it to. It does update the database when the user changes the data.

What I want to be able to do is when the user selects a day from the combo box, the NumberEditing boxes load with the values from the Database for that day. Here's where the problem is:

When the user changes the time in the NumberEditing boxes, the following procedure is called:

Private Sub CWNumEdit1_ValueChanged(Value
As Variant, PreviousValue As Variant, ByVal OutOfRange As Boolean)
Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\dates.mdb")
Set rs = db.OpenRecordset("Schedule")
While Not rs.EOF
rs.Edit
If rs!Day = cboDayEdit.Text Then
rs!ontime_1 = CWNumEdit1.Value
rs.Update
End If
rs.MoveNext
Wend
End Sub

Again, this does work well, however, when the user selects the day they want to edit from the combo box, and the combo box loads up with the values from the database like so:

While Not rs.EOF
rs.Edit
If rs!Day = cboDayEdit.Text Then
CWNumEdit1.Value = rs!ontime_1
CWNumEdit2.Value = rs!offtime_1
CWNumEdit3.Value = rs!ontime_2
CWNumEdit4.Value = rs!offtime_2
End If
rs.MoveNext
Wend

When this procedure is called, and the NumberEdit box is changed to the value in the database, it calls the CWNumEdit1_ValueChanged procedure again, because the value has changed!

How can I load up the values in those numberediting boxes without calling t
he CWNumEdit procedure?
0 Kudos
Message 1 of 3
(3,205 Views)
It sounds like you're wanting to suppress firing the ValueChanged event when you're loading data. Is that correct? If so, there's not an easy way to do this. An alternate solution to this problem would be for the form to have a boolean member variable that indicates if you're in a loading state. You could set it to true before you start loading values and then set it to false when you're finished loading values. Then in the ValueChanged event handler, you could check to see if you're in a loading state and only execute the code if you are.

- Elton
Message 2 of 3
(3,205 Views)
Elton:

Again, you are a great help. Tell your boss I said to give you a raise. I did set a boolean value before and thought of using it like that, I just thought that there might have been another way around it. It works fine now. Thanks again!

Carl Murphy
0 Kudos
Message 3 of 3
(3,205 Views)