IF, End If Select Statement (1 Viewer)

rxm01l

Registered User.
Local time
Today, 02:14
Joined
Mar 5, 2013
Messages
32
Since we changed Shift from 1 to 4 to A, B,C,D,E and F, the Calendar that belong to the respective shift is not Open up any more. No Error message either.. Doe anyone have any suggestion why? This code is behind the Dropdown combo button..

Please advise.. Thank You..

Private Sub SHIFT_SELECTION_Click()
Dim A, B, C, D, E, F As String
If IsNull(Me.SHIFT_SELECTION.Value) = True Then
MsgBox ("Select a Shift!")

Else
If Me.SHIFT_SELECTION.Value = A Then
DoCmd.OpenForm "CLONECAL1st"
End If
If Me.SHIFT_SELECTION.Value = B Then
DoCmd.OpenForm "CLONECAL2nd"
End If
If Me.SHIFT_SELECTION.Value = C Then
DoCmd.OpenForm "CLONECAL3rd"
End If
If Me.SHIFT_SELECTION.Value = D Then
DoCmd.OpenForm "CLONECAL4th"
End If
If Me.SHIFT_SELECTION.Value = E Then
DoCmd.OpenForm "CLONECAL4th"
End If
If Me.SHIFT_SELECTION.Value = F Then
DoCmd.OpenForm "CLONECAL4th"
End If
End Sub
 

Ranman256

Well-known member
Local time
Today, 05:14
Joined
Apr 9, 2015
Messages
4,339
Use SELECT CASE
Or
Use a combo box,with 2 columns,
User sees col1, the value is in col2.
Then
Docmd.openForm cboBox.
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,367
values of A B C etc will be strings. You are referring to them as variables. Also that code won't compile you are missing an End If.

Code:
Private Sub SHIFT_SELECTION_Click()

    Select Case Me.SHIFT_SELECTION

        Case "A"
            DoCmd.OpenForm "CLONECAL1st"
        Case "B"
            DoCmd.OpenForm "CLONECAL2nd"
        Case "C"
            DoCmd.OpenForm "CLONECAL3rd"
        Case "D", "E", "F"
            DoCmd.OpenForm "CLONECAL4th"
        Case Else
            MsgBox ("Select a Shift!")
    End Select

End Sub
 

rxm01l

Registered User.
Local time
Today, 02:14
Joined
Mar 5, 2013
Messages
32
OMG, Minty, you are the greatest.. Thank You.. I used your code.. it's working.. I'm new in VBA world..
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,367
Personally I would have one form and filter its records to the appropriate shift when opening it. Then you only have one form to maintain and update.

Currently you would have to copy and paste the form again for shift G H ....X Y Z etc.

Have a look at the Where clause in the OpenForm properties.
 

rxm01l

Registered User.
Local time
Today, 02:14
Joined
Mar 5, 2013
Messages
32
I'm 100% agree with you. I will take a look at that option as my knowledge in VBA getting better.. For now, I have to stay with 7 calendars for 7 shifts, since each shift starting at Diff time.LOL.. Thank You Minty.
 

Users who are viewing this thread

Top Bottom