Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to set form property.visible from no to yes 1

Status
Not open for further replies.

jrtimes2

Technical User
Mar 21, 2003
2
US
I'm trying to write a macro that will change the Visible property of a subform from "no" to "Yes". I've attempted to use the SetValue function in the macro.

In the "Item" field of the Macro, I used the format Forms!FormName.Visible , where "FormName" is the name of the form I'm using as the subform. In the "Expression" field of the macro, I've tried setting the value to yes, true and -1.

I am getting two error messages. First I get an error message that "Production/Release Data can't parse the expression". When I add brackets around the form name, the software will automatically add brackets around the property name [Visible], but then the macro will save.

The second error message occurs when I try to run the saved macro, I get a message that "the object I referenced in the Visual Basic procedure as an OLE object isn't an OLE object".

Is there a different function (other than SetValue) I should try? Or do I have the wrong syntax in the Item field of the macro?

Thanks in advance for the help... much appreciated.
JR
 
JR

Are you trying to toggle the subform visibility based on a condition on the main form or from a button?

In either case, you can do this in VBA code.

Create a control button on your main form. On its property sheet click on the Event tab then in its On Click event, select [Event Procedure]. Click on the down arrow to the right of this box and a code window will open to the On Click subroutine for your control button.

You will need similar code to the following:

If [Your subform name here].Form.Visible = True Then
[Your subform name here].Form.Visible = False
Else
[Your subform name here].Form.Visible = False
End If

Me.Repaint



HTH,

Vic
 
Vic,

Thanks bunches for the tip. It works well! I was trying to toggle the subform visibility from a command button linked to a macro. I did just as you suggested, and voila!

It did bring up another question... Can I have a control on the subform to toggle the visibility back to false? I tried to add a button, patterning the code to what you provided, and I get an error message that "You can't hide a control that has the focus".

Here's the code I tried:
If [Forms]![FormName].[SubformName].Form.Visible = True Then
[Forms]![FormName].[SubformName].Form.Visible = False
Else: [Forms]![FormName].[SubformName].Form.Visible = False
End If

My application needs several different subforms, depending on the type of data entered. I'm trying to emulate a pop-up form that one can select the subform they need by clicking a button, fill out, and close the subform to continue.

Thanks again for your very good advice! Much appreciated.
JR
 
JR

Haven't tried this, but in the button code on the subform, try setting the focus to a control on the main form just before you make the subform invisible.

It might work. But if you get that same message, you'll have to rethink your design.

HTH,

Vic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top