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

switching between form and datasheet view

Status
Not open for further replies.

DRH192

Programmer
Apr 25, 2005
96
GB
Hello,

Does anyone know how to use the double click event of a form record selector to change the view from datasheet to form view. I know you can make two forms and just swap the control source and then requery. just thought there must be a more obvious solution, but i cant find it.

I am aware of the following but they dont seem to work. I recieve error messages such as cant switch view at this time etc

docmd.runcommand accmddatasheetview
' and
docmd.runcommand accmdformview

cheers mates
 
The recordselector does not have any events. As stated in thread705-1099035, you could try the forms on click event - this will fire when the record selector is clicked in both views - though probably when clicking on someting else, too, but not while working with the data...

Check which view is selected with

[tt]if me.currentview = 1 then
docmd.runcommand accmddatasheetview
else
docmd.runcommand accmdformview
end if[/tt]

As for the error about not being able to change view - it is probably not able to change the view due to some reasons - not possible from the selected event, there's something else preventing it (unsaved changes, validation...???)...

Roy-Vidar
 
Sorry when i said the record selector, i was talking about the on double click event of the form.

I will try this code, but i suspect it will not work as it is almost identicle to code i have used before.

Maybe i should have mentioned that this is a one to many form, i.e. a property with many contacts. so the default view for the contacts is datasheet, and when the form is double clicked, it will switch to form view to display all the records as some are hidden in datasheet view.

thanks for the reply
 
Ah - subforms, it's easier if you state so a bit more explicitly (faq181-2886 #14) ;-)

[tt]if me.currentview = 1 then
docmd.runcommand accmdsubformdatasheetview
else
docmd.runcommand accmdsubformformview
end if[/tt]

Roy-Vidar
 
OK so the code is perfect when working on the parent form but can't get it to work on the subform. i'll play around and see what i need to do to get this code to work

cheers
 
i'm sorry i cant see those commands in the object inspector.

the closest i could get was

If Me.CurrentView = 1 Then
DoCmd.RunCommand acCmdFormView
DoCmd.RunCommand acCmdSubformDatasheet
Else
DoCmd.RunCommand acCmdFormView
End If

and that returned the error "The command 'SubformDatashee' isnt available now" code 2046

 
If Me.CurrentView = 1 Then
DoCmd.RunCommand acCmdSubformDatasheet
Else
DoCmd.RunCommand acCmdFormView
End If

will make the form change from form view to datasheet view but not the other way.

any ideas why it only works one way?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top