Setting An Object w/ A Variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to set a Object by using a variable and am having some trouble.
Here are the scripts I am trying to use

Private Sub Initilize_Click()
strFormName = Me.Form.Name 'Get current Form name
Set objFormName = strFormName
End Sub

With the above I get run time error 13 -> Type mismatch.

So what I did next was add the DIM statement below

Private Sub Initilize_Click()
strFormName = Me.Form.Name 'Get current Form name
Dim objFormName As Object
Set objFormName = strFormName

End Sub

Now I get error runt time error 424 -> object required.

Is there a way to set and Object with some other variable like above? or is
there a way to manual set an object i.e. Set objFormName = "frmMain", which
also gives a type mismatch error?
 
Why are you trying to create an instance objFormName when you can simply use
Me?

If you really need it, try:

Private Sub Initilize_Click()
strFormName = Me.Form.Name 'Get current Form name
Dim objFormName As Object
Set objFormName = Forms(strFormName)
End Sub
 
Back
Top