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!

Form unload error: 361. Why?

Status
Not open for further replies.

javanic

Programmer
Jun 18, 2003
13
US
Hi.

In Excel VBA, I have this code:
Code:
Private Sub cmdExit_Click()
   Unload frmMyForm
End Sub

It works in Excel. But in Access, I have the identical code, and it doesn't work. It gives me Run Time Error 361 - Can't load or unload this object.

Thanks for you help in advance,


- javanic -
 
In Access it should be:

Private Sub cmdExit_Click()
Docmd.Close acForm, frmMyForm
End Sub

Bill
 
Thanks, billpower.

With the addition of quotes around the form name, your code worked.

Code:
Private Sub cmdExit_Click()
   Docmd.Close acForm, &quot;frmMyForm&quot;  <--- quotes needed
End Sub



- javanic -
 
Hi javanic,

Not meaning to be pedantic myself, but I didn't know how you were setting the variable frmMyForm (and still don't)when I made my suggestion. In future maybe you can supply full code when seeking help. frmMyForm set in the manner below doesn't need quotes, placed in the On Click event of a button would close the form containing the button.

Dim frmMyForm As String
frmMyForm = Me.Name
DoCmd.Close acForm, frmMyForm '<--- quotes not needed

Glad it worked in a round about way.

Bill
 
Thanks again, billpower.

I'm learning more each time. When I first tried the code you gave me, Access still complained. I dug deeper and caught sight of the word &quot;string&quot; in help. I was using the actual form name, not a variable, as I would in Excel VBA. Apparently in Access, and with the DoCmd, it is looking for the name of the form in a string formatted variable.

What I showed in the first post *was* the full code--as I had incorrectly written it, of course. :)


- javanic -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top