HVMP
HVMP

Reputation: 72

Shorten object path name in Access

I've been looking for a while but have a feeling I don't know the proper way to search what I'm looking for. So, I have this code:

Private Sub AB1_dMnmsSfHrbr_Click()
    If Forms!frmab1!AB1_dMnmsSfHrbr.Value = -1 Then
        Forms!frmab1!AB2a_expTrtmnt.Enabled = True
        Forms!frmab1!AB5a_invPrice.Enabled = False
    ElseIf Forms!frmab1!AB1_dMnmsSfHrbr.Value = 0 Then
        Forms!frmab1!AB2a_expTrtmnt.Enabled = False
        Forms!frmab1!AB5a_invPrice.Enabled = True
    End If
End Sub

I want to be able to shorten Forms!frmab1 to something shorter like "FAB1" so that I can type my likes like:

FAB1!AB2a_exptrtmnt.enabled = true

How do I do it?

Thanks!

Upvotes: 2

Views: 39

Answers (1)

saamorim
saamorim

Reputation: 3905

You can either create a local variable or use the with statement

Local Variable:

Private Sub AB1_dMnmsSfHrbr_Click()

    Dim FAB1 as Form
    Set FAB1 = Forms!frmab1

    If FAB1!AB1_dMnmsSfHrbr.Value = -1 Then
        FAB1!AB2a_expTrtmnt.Enabled = True
        FAB1!AB5a_invPrice.Enabled = False
    ElseIf FAB1!AB1_dMnmsSfHrbr.Value = 0 Then
        FAB1!AB2a_expTrtmnt.Enabled = False
        FAB1!AB5a_invPrice.Enabled = True
    End If
End Sub

With Statement:

Private Sub AB1_dMnmsSfHrbr_Click()

    With Forms!frmab1

        If !AB1_dMnmsSfHrbr.Value = -1 Then
            !AB2a_expTrtmnt.Enabled = True
            !AB5a_invPrice.Enabled = False
        ElseIf !AB1_dMnmsSfHrbr.Value = 0 Then
            !AB2a_expTrtmnt.Enabled = False
            !AB5a_invPrice.Enabled = True
        End If

    End With
End Sub

Upvotes: 2

Related Questions