Link to home
Start Free TrialLog in
Avatar of Mike Rudolph
Mike RudolphFlag for United States of America

asked on

Access DoCmd.Close Run-time error '13' type mismatch

Experts,

Not why I am getting this error message.

Debug highlights on   DoCmd.Close "Welcome"

Of course when I just use DoCmd.Close the form that just opened is closes.

I really just want to open the frmVisitorlog and close the Welcome forms. I even tried to reverse the two lines and I still get the same message.

How can I fix this?

Thanks!


Private Sub Command21_Click()
  DoCmd.OpenForm "frmVisitorLog"
  DoCmd.Close "Welcome"
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Farzad Akbarnejad
Farzad Akbarnejad
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or, if  command button is a form "Welcome", you may use the codes below as well:

Private Sub Command21_Click()
  DoCmd.Close
  DoCmd.OpenForm "frmVisitorLog"
End Sub


Sincerely,

Ed
Sorry, it should be read as

Or, if  the command button is in a form "Welcome", you may use the codes below as well:
shogun5,

<No points needed>

FarzadA suggestion surely solves the issue. Considering that you mention about reversing the two lines, I posted here the other way. Just for information and reference purposes.

Sincerely,

Ed
Avatar of Mike Rudolph

ASKER

FarzadA,

Yep! That was it. May I ask why this will work

DoCmd.OpenForm "formName"

but I get an error here:

DoCmd.Close "Welcome"

and much add acForm like

DoCmd.Close acForm "Welcome" ?

Thanks!
Hello,
DoCmd.OpenForm knows that it must open form so you need only pass form name to it. But DoCmd.Close closes more than form objects. You must pass what type of objects that you want close. Passing form name instead of object type will cause type mismatch in passing arguments to DoCms.Close method.

-FA
FarzadA,

Thank you. I understand now.

Mike