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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Form View in Code ...

Status
Not open for further replies.

rick360

Technical User
May 24, 2004
11
US
Is it possible to change a form's view from datasheet-view to form-view in code?
I have a form with a sub-form I would like to be able to change the view in code of the sub-form so the user doesn't have to or put a button on the main form to make it easy for them. Can this be done?

Thanks in advance,
Rick
 
It seems Access won't let you do that unless you're in design view. I don't know how to programatically change the view you're in and then change the form... but there's another way. You could try this:

- create two equal subforms, one with a datasheet view another with form view.
- Link one of them to the main form.
- Create a button that when pressed will change the subform's "sourceobject" to the name of the other form.

Voila! You can then change the subform with a click of a button. It's a workaraound, but the only way I found.

Is that what you want?
 
Yes, if Access wont let you do it directly, then I guess thats what I will do. I was thinking some type of form swapping might be how I would have to do it. I will give it a try.

Thanks,
Rick
 
How are ya rick360 . . . . .

First, make sure the forms [blue]Views Allowed[/blue] property is set to [purple]Both[/purple].

Your code lines of interest are (form already open):

DoCmd.RunCommand acCmd[blue]Form[/blue]View
DoCmd.RunCommand acCmd[blue]DataSheet[/blue]View

Calvin.gif
See Ya! . . . . . .
 
Yeah, I see that works, but how do you apply it to the subform?
 
How are ya norwood . . . . .

It does'nt work for subform . . . . sorry.

What you can do in code is, close the main form, open the subform in design view, change the [blue]Default View[/blue], close the subform, then open the main form. You can hide all the opening & closing using the [blue]Application.Echo[/blue] method. Its the long way around but can be done.

[blue]rick360 & norwood[/blue] . . . . Out of curiosity, [purple]why would you want to do this?[/purple]

Calvin.gif
See Ya! . . . . . .
 
Aceman,
I was building a search form, for an Instrument database, with criteria boxes in the upper part of the form and the results to show up in the sub-form(bound to the query) in list view. I wanted the user to be able to scroll thru the results and select an item by double-clicking it to switch to form view to see that one item in a form which would be arranged for viewing a single item. There may be different ways of doing the same thing, this was how I thought it would be easist to use, not necessarily easiest to program. I would appreciate any other suggestions.

Thanks,
Rick
 
Hi!

You could try using two subforms, place them on top of eachother, and change their visible property. You'd need to setfocus to another control temporarily for this to work, and apply filter..., something like this:

[tt]me.parent("txtSomeControl").setfocus
me.visible=false
me.parent("frmOtherSubForm").form.filter="idfield = " & me("txtId").value
me.parent("frmOtherSubForm").form.filteron=true
me.parent("frmOtherSubForm").visible=true
me.parent("frmOtherSubForm").form("txtSomeControl").setfocus[/tt]

then just reverse the process on a relevant event to make the other subform visible again

Roy-Vidar
 
Why not use a subform on continuous form view? I think it looks better than datasheet view. You could also use a listview control for that...

With a subform on countinuous form view you can have a button that when clicked will open that record on another form or you can have it so that when the user clicks on the line, it open the form with that record (the 'onclick' event). With a listview control you can make it so when the user clicks on a line it opens a form with that record.

Can we upload things on a thread? I could send you a couple of screenshots of both approaches if you'd like.
 
Or . . . .

Instead of going through the rigors of hiding forms & reversing & all, just make a modal pop-up form locked to your selection via [blue]Primary Key[/blue] (certainly the easiest).

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top