Full Version: Form opening in wrong view.
UtterAccess Forums > Microsoft® Access > Access Forms
I have a form created in datasheet view based on one table. The properties of the form are set to Datasheet view. When I open the form by double clicking on the form in the list of all forms, it opens as it should in datasheet view. However, if I open the form by using an OnClick code for a command button it opens in Single Form view. Here is the code that I have behind the button:
Private Sub Command0_Click()
DoCmd.OpenForm ("ADMcommitteeMemberForm"), acPreview
DoCmd.Close acForm, "ADMcommitteeMainMenu"
End Sub
Does anyone know a solution to this problem so that the form opens in datasheet view rather than single form view?
Thanks in advance!
Try changing it to just..............
oCmd.OpenForm "ADMcommitteeMemberForm"
Hey, sorry.. Thats the original code that I had in place, I was trying to find a solution so I put the preview, which didn't help. I switched it back to the code that you just gave me and it's still not working properly. It's still opening it in Single Form ( ) view rather than datasheet, as it is in the properties.
I think I'd try creating a new form set to Datsheet view (bound to the same table as the original form) and see if that one opens as expected. If it does, I'd scrap the original...........
Thanks for the response, I just tried to do this and I am getting the exact same results. I assume that I'm missing some code to tell it to open as datasheet. I did find a solution, but its more of a work-around by not using code. I remember running into this problem before and I created a macro to get around it. When creating a macro to open a form, the macro asks what you want the form to be displayed as, where you can select Datasheet. Now when you open the form using a command button with a macro, it opens as a datasheet. I'd prefer to use code, but this works. If you find another solution I would love to have it for furture reference as to avoid this problem.
Thanks again,
Try changing it to
oCmd.OpenForm "ADMcommitteeMemberForm" , acFormDS
Now that works a treat! (wish they listed that constant when you are writing the code)
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.