Sub not working

kit_sune

Registered User.
Local time
Today, 11:22
Joined
Aug 19, 2013
Messages
88
I have two subroutines, each one references the type of form that the call is embedded in. However, one works and one doesn't.

This works:
Code:
Public Sub doLockout(ByRef theForm As Form, ByVal isLocked As Boolean)
' In separate shared module
  Dim ctl As Control
  For Each ctl In theForm.Controls
    Select Case ctl.ControlType
      Case acTextBox, acComboBox
        ctl.Enabled = Not isLocked
    End Select
  Next ctl
End Sub

Code:
Private Sub Lockout_Check_Click()
  doLockout Me.Form, Me.Lockout_Check
End Sub

This doesn't:
Code:
Public Sub backToHub(ByRef theForm As Form)
DoCmd.Close acForm, theForm
DoCmd.OpenForm "TechSupportHub_Form"
End Sub
Code:
Private Sub Back_Button_Click()
backToHub Me.Form
End Sub

What am I missing?

Thanks,
~Kit
 
Last edited:
"Doesn't work" is not enough info. It's like telling your doctor you feel sick. Of course you do, you're at the doctor.
hth
 
"Doesn't work" is not enough info. It's like telling your doctor you feel sick. Of course you do, you're at the doctor.
hth

Appologies,

I was distracted at that time.

I get the error "An Expression you entered is the wrong data type for one of the arguments."

When I examine the debugger it has "DoCmd.Close acForm, theForm" highlighted, and when I hover over the code it appears to be displaying "acForm = 2"
 
Public Sub backToHub(ByRef theForm As Form)
DoCmd.Close acForm, theForm
DoCmd.OpenForm "TechSupportHub_Form"
Private Sub Back_Button_Click()
backToHub Me.Form
End Sub
You don't want to pass a form, you want to pass the forms name as String.
Code:
Public Sub backToHub(ByRef theForm [COLOR="Red"]As String[/COLOR])
DoCmd.Close acForm, theForm
DoCmd.OpenForm "TechSupportHub_Form"
End Sub
Private Sub Back_Button_Click()
backToHub [COLOR="red"]Me.Form.Name[/COLOR]
End Sub
 
The second parameter of DoCmd.Close is the name of the object, which is a string, so you could try . . .
Code:
Public Sub backToHub(ByRef theForm As Form)
   DoCmd.Close acForm, [COLOR="Red"]theForm.Name[/COLOR]
   DoCmd.OpenForm "TechSupportHub_Form"
End Sub
 
Also, you don't need Me.Form. Me is sufficient.
Code:
Private Sub Back_Button_Click()
   backToHub Me
[COLOR="Green"]   'not
   'backToHub Me.Form
[/COLOR]End Sub
 

Users who are viewing this thread

Back
Top Bottom