Error of Object Variable or With block variable not set

M

Michael Banks

I am trying to just make a short cut in my code so that I don't have to
reference frm's and subfrm's over and over again.

I have created a public control called stDocFrm and stDocSubfrm as
Control. I then pass this control up into a public funtion and perform
several tasks on it (do a recordsetclone.recordcount, set it visible,
move focus, etc.)

Here is the code:

Public stDocName As String
Public stDocFrm As Control
Public stDocSubfrm As Control

Private Sub cmdTransformers_Click()
On Error GoTo Err_cmdTransformers_Click
stDocName = "frmTransformers"
DoCmd.OpenForm stDocName, , , stLinkCriteria

stDocFrm = Forms!frmtransformers <---Errors out here "Object
Variable or With block variable not set"
stDocSubfrm = Forms!frmtransformers!subfrmTransformers

Call EquipmentCountSub

Exit_cmdTransformers_Click:
Exit Sub

Err_cmdTransformers_Click:
MsgBox Err.Description
Resume Exit_cmdTransformers_Click
End Sub


Please offer up any opinions you have. Thanks
Mike
 
R

Rick Brandt

Michael Banks said:
I am trying to just make a short cut in my code so that I don't have to
reference frm's and subfrm's over and over again.

I have created a public control called stDocFrm and stDocSubfrm as
Control. I then pass this control up into a public funtion and perform
several tasks on it (do a recordsetclone.recordcount, set it visible,
move focus, etc.)

Here is the code:

Public stDocName As String
Public stDocFrm As Control
Public stDocSubfrm As Control

Private Sub cmdTransformers_Click()
On Error GoTo Err_cmdTransformers_Click
stDocName = "frmTransformers"
DoCmd.OpenForm stDocName, , , stLinkCriteria

stDocFrm = Forms!frmtransformers <---Errors out here "Object
Variable or With block variable not set"
stDocSubfrm = Forms!frmtransformers!subfrmTransformers

Call EquipmentCountSub

Exit_cmdTransformers_Click:
Exit Sub

Err_cmdTransformers_Click:
MsgBox Err.Description
Resume Exit_cmdTransformers_Click
End Sub

First off your are dimming stDocFrm as a Control and then trying to set it to a Form
object. Second, when making object assignments you need to use...

SET SomeVar = SomeObject

....rather than just...

SomeVar = SomeObject.
 
M

Michael Banks

Rick,

Can you elaborate a little more for me please? I have changed the code to Set stDocFrm
= Forms!frmTransformers but now I am getting a "Type MisMatch" error. stDocFrm is still
dimmer Control.

Thanks
Mike
 
M

Michael Banks

I changed the dim stdocfrm to be as form and kept stdocsubfrm as control and everything is
working now. It took me a little bit to see what you ment by your response. Thanks for
your help.

Mike
 

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