Can you open and close subforms in VB? (1 Viewer)

shacket

Registered User.
Local time
Today, 18:06
Joined
Dec 19, 2000
Messages
218
I want to, using VB, open and close subforms on a main form and place them in a certain spot. Is that possible?

Dave
 

Jack Cowley

Registered User.
Local time
Today, 18:06
Joined
Aug 7, 2000
Messages
2,639
You can place the various subforms where you want them on your main form. Then set their Visible property to No. You can 'open' or 'close' them using code to set their Visible property to Yes or No. The code would look something like this:

Me.Subform1.Visible = True
 

BillNorton

Registered User.
Local time
Today, 18:06
Joined
May 23, 2001
Messages
27
Are you actually trying to move the subform to a different spot on the form? Well, this would do it:

Me.sfWhatever.Left = 2000

The number you are setting it to is in twips, I believe.

Bill Norton
Austin, TX
 

shacket

Registered User.
Local time
Today, 18:06
Joined
Dec 19, 2000
Messages
218
Thanks for your responses. I have a main form now with about 10 subforms stacked on top of each other, of which only 1 is visible based on a choice in a listbox.

What I am trying to do is lessen the work the form has to do when it opens by not having to open all 10 subforms (even if they are invisible).

I have two other ideas. Maybe you can give me your thoughts on these:

1. Have 1 subform and change the RecordSource in code. Unfortunately, I need to give users design permissions on that form for it to work for them. As long as I have the original, they can mess with design (if they can figure out how to get there) I guess.

2. Open up another form based on the main form. (i.e. a "subform" that is not ON the main form, but acts the same way). I would need to size and place those forms, though. Can I open a form to a specific size and place on the screen in its properties or VB?

Dave
 

Atomic Shrimp

Humanoid lifeform
Local time
Today, 18:06
Joined
Jun 16, 2000
Messages
1,954
This works:

Code:
Me.MySubFormName.SourceObject = "NameOfForm"
Me.MySubFormName.Requery

it will open up the subform named NameOfForm into the space where the previous one was (only really works well if all of your subforms are so similar size/shape.
 

BillNorton

Registered User.
Local time
Today, 18:06
Joined
May 23, 2001
Messages
27
Go with Mike's approach, and perhaps set the subform's RecordSource at the same time:

Me.MySubFormName.SourceObject = "NameOfForm"
me.mySubFormName.RecordSource = "SELECT X, Y, Z, FROM ... WHERE " & lsWhereClause
Me.MySubFormName.Requery

Your usere will NOT need any kind of special priviliges to do this. These are all run-time changes and won't be saved when the user exits.

Bill Norton
Austin, TX
 

shacket

Registered User.
Local time
Today, 18:06
Joined
Dec 19, 2000
Messages
218
That is the direction I am headed. What I don't understand is this: changing the SourceObject for an existing subform is considered a design change. When I tried this before (with a user's login), I got a message that they did not have priviledges to make design changes. What am I missing?

Dave
 

BillNorton

Registered User.
Local time
Today, 18:06
Joined
May 23, 2001
Messages
27
First of all let me correct a coding error. To change a subform's RecordSource try this:

Me.mySubFormName.Form.RecordSource = "SELECT X, Y, Z, FROM ... WHERE " & lsWhereClause

Now, when you say that changing the SourceObject for an existing subform is considered a design change, are you talking about actually clicking on the design view button and changing the SourceObject there? If so, then, yes, that would be a design change, and your users would need privileges.

The approach we are talking about is only a run-time change. Nothing about the form gets permanently modified, and one user's changes are invisible to other users. The users don't need special privilege to do this.

Bill Norton
Austin, TX
 

Users who are viewing this thread

Top Bottom