Access (2013) Crashes on pressing Button that runs VBA Code.... (1 Viewer)

vito1010

Registered User.
Local time
Yesterday, 20:13
Joined
Aug 14, 2014
Messages
33
Access (2013) Crashes on pressing Button that runs VBA Code UNLESS I view the VBA code before I hit the button.
It works fine after I come back from viewing the code in VBA.
Here is the VBA:

Private Sub ShowIt_Click()

If ShowIt = False Then
cUSB.Visible = True
CFireWire.Visible = True
cThunder.Visible = True
cHDMI.Visible = True
cSIM.Visible = True
cTouch.Visible = True
eSat.Visible = True
cWWoB.Visible = True
cSD.Visible = True
cMSD.Visible = True
cWiFi.Visible = True
cEther.Visible = True
cBT.Visible = True
PCCard.Visible = True
cOther.Visible = True
OtherDes.Visible = True
HDMISize.Visible = True
SimSize.Visible = True
USBType.Visible = True
USBCount.Visible = True
ThunderCount.Visible = True
cWiFiExt.Visible = True
Label103.Visible = True
ShowIt.Caption = "Show Notes"
Label103.Caption = "Connections"
Notes.Visible = False
Label103.Width = 1200
RDPort.SetFocus

Else
If ShowIt = True Then
cUSB.Visible = False
CFireWire.Visible = False
cThunder.Visible = False
cHDMI.Visible = False
cSIM.Visible = False
cTouch.Visible = False
eSat.Visible = False
cWWoB.Visible = False
cSD.Visible = False
cMSD.Visible = False
cWiFi.Visible = False
cEther.Visible = False
cBT.Visible = False
PCCard.Visible = False
cOther.Visible = False
OtherDes.Visible = False
HDMISize.Visible = False
SimSize.Visible = False
USBType.Visible = False
USBCount.Visible = False
ThunderCount.Visible = False
cWiFiExt.Visible = False

Notes.Visible = True
Label103.Caption = "Notes"
ShowIt.Caption = "Show Connections"
Label103.Width = 600
Notes.SetFocus

Else
End If
End If

End Sub



Any help would be appreciated
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:13
Joined
Feb 28, 2001
Messages
27,131
Omitting the bulk of that code, you have an IF/THEN/ELSE/ELSE/END IF/END IF - which means that the second ELSE is missing an IF. Perhaps you were thinking of an ELSEIF in place of the first ELSE?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:13
Joined
Jul 9, 2003
Messages
16,271
I don't think you need any Else's, just use IF's ...
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:13
Joined
Jul 9, 2003
Messages
16,271
Your code could be simplified by adding an "X" to each controls Tag property.

See my blog for more info:-

 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:13
Joined
May 7, 2009
Messages
19,228
Is ShowIt control a Checkbox?
Checkbox don't Have Caption Property.
If you are using A2010 or later, you can change the Caption of label associated with ShowIt:

If Me.ShowIt Then
Me.ShowIt.Controls(0).Caption = "Show Notes"
Else
Me.ShowIt.Controls(0).Caption = "Show Connections"
End If
 

Eugene-LS

Registered User.
Local time
Today, 03:13
Joined
Dec 7, 2018
Messages
481
Access (2013) Crashes on pressing Button that runs VBA Code
If "ShowIt" is button - try code:
Code:
Private Sub ShowIt_Click()
' ... yoyr code description
'----------------------------------------------------------------------------------------------
Dim blnShowIt As Boolean

On Error GoTo ShowIt_Click_Err

' set value to variable from ...
    blnShowIt = Not Me.Notes.Visible
   
    Me.cUSB.Visible = Not blnShowIt
    Me.CFireWire.Visible = Not blnShowIt
    Me.cThunder.Visible = Not blnShowIt
    Me.cHDMI.Visible = Not blnShowIt
    Me.cSIM.Visible = Not blnShowIt
    Me.cTouch.Visible = Not blnShowIt
    Me.eSat.Visible = Not blnShowIt
    Me.cWWoB.Visible = Not blnShowIt
    Me.cSD.Visible = Not blnShowIt
    Me.cMSD.Visible = Not blnShowIt
    Me.cWiFi.Visible = Not blnShowIt
    Me.cEther.Visible = Not blnShowIt
    Me.cBT.Visible = Not blnShowIt
    Me.PCCard.Visible = Not blnShowIt
    Me.cOther.Visible = Not blnShowIt
    Me.OtherDes.Visible = Not blnShowIt
    Me.HDMISize.Visible = Not blnShowIt
    Me.SimSize.Visible = Not blnShowIt
    Me.USBType.Visible = Not blnShowIt
    Me.USBCount.Visible = Not blnShowIt
    Me.ThunderCount.Visible = Not blnShowIt
    Me.cWiFiExt.Visible = Not blnShowIt
    Me.Label103.Visible = Not blnShowIt
    Me.Notes.Visible = blnShowIt

    If blnShowIt = False Then
        Me.RDPort.SetFocus '
        Me.ShowIt.Caption = "Show Notes"
        Me.Label103.Width = 1200
        Me.Label103.Caption = "Connections"
    Else 'If blnShowIt = True
        Me.Notes.SetFocus
        Me.ShowIt.Caption = "Show Connections"
        Me.Label103.Caption = "Notes"
        Me.Label103.Width = 600
    End If

ShowIt_Click_End:
    Exit Sub

ShowIt_Click_Err:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Sub" & _
           "ShowIt_Click - [ your form name ... ].", vbCritical, "Error!"
    'Debug.Print "ShowIt_Click_Line: " & Erl & "."
    Err.Clear
    Resume ShowIt_Click_End
End Sub
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:13
Joined
Jul 9, 2003
Messages
16,271
If "Show it" is a command button, then you need code similar to this:-


As I suspect ArnelGP meant....
 

Users who are viewing this thread

Top Bottom