I am new at visual basic and am trying some new things with it.
I have created a few combo boxes in my form with yes/no choices. The text input boxes are not visible unless the yes is selected and then they show up.
Code that I have for this: vb Code:
- '--------------------------------------------------------------------
- Private Sub Knox_Box_AfterUpdate()
- If Me.Knox_Box = "Yes" Then Me.Knox_Box_Location.Visible = True Else Me.Knox_Box_Location.Visible = False
- End Sub
- '---------------------------------------------------------------------
- Private Sub Knox_Box_BeforeUpdate(Cancel As Integer)
- If Me.Knox_Box = "yes" Then
- If Trim(Nz(Me.Knox_Box_Location)) = "" Then
- MsgBox "Knox Box Location is required when Knox Box is Yes."
- Cancel = False
- End If
- End If
- End Sub
- '---------------------------------------------------------------------
The problem I am having (and don't know if it feasible or not) is that for another combo box selection I have 3 choices: yes/no/partial. I have 2 text input boxes referencing different fields in the table for data storage. I want it to show the one box if yes is selected, both boxes if partial is selected, and none if no is selected.
Here is what i have so far, but have tried numerous methods. The best I get is for the 1 box to open when yes is selected, none to show when no is selected, and none to show when partial is selected which is not what I am looking to do. The message box works fine for yes, no, and partial.
problem code: vb Code:
- '-------------------------------------------------------------------------
- Private Sub Sprinkler_AfterUpdate()
- If Me.Sprinkler = "Yes" Then Me.FDC_Location.Visible = True
- If Me.Sprinkler = "No" Then Me.FDC_Location.Visible = False
- If Me.Sprinkler = "Partial" Then
- Me.FDC_Location.Visible = True And Me.Partial_Sprinkle.Visible = True
- Else
- Me.FDC_Location.Visible = False And Me.Partial_Sprinkle.Visible = False
- End If
- End Sub
- -------------------------------------------------------------------------
- Private Sub Sprinkler_BeforeUpdate(Cancel As Integer)
- If Me.Sprinkler = "yes" Then
- If Trim(Nz(Me.FDC_Location)) = "" Then
- MsgBox "FDC Location is required when Sprinkler is Present."
- Cancel = False
- End If
- End If
- If Me.Sprinkler = "Partial" Then
- If Trim(Nz(Me.FDC_Location)) = "" Then
- MsgBox "Box #1) FDC Location is required when Sprinkler is present." & vbCrLf & "Box #2) List Locations covered by Sprinkler."
- Cancel = False
- End If
- End If
- End Sub
- '-----------------------------------------------------------------------
Any help would be appreciated.