Setting An Object w/ A Variable

J

jutlaux

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?
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top