Changing Forms CurrentView Property Using VBA

OK, have what I hope is an easy question, though I can't seem to figure out how to do it. I have an application, in which are two forms (FormA and FormB). What I would like is to have a button on FormA that, when clicked, will set the currentview of FormB to Design Mode. In other words, I want users to be able to click the button on FormA and have that button click show FormB in Design Mode. Hopefully, that's clear enough. Here is the code I am using to (unsuccessfully) accomplish this (button name is: dButton).

Private Sub dButton_Click()
     Forms!FormB.CurrentView = 0 'Set FormB to Design Mode
End Sub

My problem is that when the button is clicked, I get an error message stating that the CurrentView property is read-only and may not be changed. Is this true? If so, how would I accomplish the desired result?

Any and all help would be greatly appreciated. I have allocated 175 points for the answer to this rather annoying question.

As always, thank you!
Who is Participating?
ok ... so check to see if the form is open and then close it and reopen in design view ... are you also opening it hidden?

If SysCmd(acSysCmdGetObjectState, acForm, "FormB") <> 0 Then
    'save and close any pending changes
    DoCmd.Close acForm, "FromB", acSaveYes
End If

'reopen in hidden design mode.
DoCmd.OpenForm FormName:="FormB", _
               View:=acDesign, _

Why do you want to open in Design View?

DoCmd.OpenForm FormName:="FormB", View:=acDesign

Painfree888Author Commented:


My example is a simplified version of what I am and want to do in my app. The form opens in design view because I am creating objects on the form and then displaying them based on which button a user clicks. I have been using the method you describe, OpenForm, but that appears to cause a problem with window spawning. In other words, at a certain point, when the user clicks the button, fifty form windows appear to spawn (they appear down in the task bar - fifty or so instances of the window I am opening in design mode).

So, my thought was, instead of using the OpenForm method, which appears to be causing me problems, instead I would open the form just once and then switch back and forth between normal and design mode. One way I had thought to do this was to set the CurrentView property. Sadly, it is read-only. So, was wondering if there is another way to get a form into design mode without using the OpenForm method.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.