I am working on access 2010 database. Im fairly new to this and have no much knowledge of VBA.
I have a form (based on a query) that display ina text box the test frequency of certain items. it's named "TestFrequency"
Then I have 3 combo boxes (named: Year1 , Year2 and Year3, respectively).
I had added a button and created an event en "Onclick", what im trying to do is to set the value of the comboboxes depending on the testfrequency value. I also added some messagebox to popup when the event is done.
Im trying with the following code but is not working:
Private Sub Reset_Click()
Dim Response As VbMsgBoxResult
Response = MsgBox("Do you want to reset planning to default test frequency?", vbQuestion + vbYesNo, "Planning Settings")
If Response = vbNo Then Exit Sub Else
Dim ctrl AS Controls
For Each ctrl From Me.Controls
If TestFrequency.Value = "Test Annually" Then
Me.Year1.Value = "Yes"
Me.Year2.Value = "Yes"
Me.Year3.Value = "Yes"
ElseIf TestFrequency.Value = "Test Every 2 years" Then
Me.Year1.Value = "No"
Me.Year2.Value = "Yes"
Me.Year3.Value = "No"
ElseIf TestFrequency.Value = "Test every 3 years" Then
Me.Year1.Value = "No"
Me.Year2.Value = "No"
Me.Year3.Value = "Yes"
ElseIf TestFrequency.Value = "Ad-hoc" Then
Me.Year1.Value = "No"
Me.Year2.Value = "No"
Me.Year3.Value = "No"
End If
Next ctrl
MsgBox "Settings were changed.", vbInformation
End If
End Sub
Can somebody please help me? thanks!
Me.as its within the codes of the form. I don't understand your logic in the form presentation, shouldn'tTestFrequencybe a ComboBox and when selected/changed, changes the other comboboxes (I would use CheckBox for Year1, Year2, Year3)? - PatricK