Command Button not working with VBA

gpurger

Registered User.
Local time
Today, 02:03
Joined
Apr 21, 2004
Messages
66
I am trying to create a close form command button. If I use the wizard I get the 'user defined type not defined '.
If I create a macro it works.
Convert to VBA and it comes up with the same error.
To make things worse it is only this form thats affected.:confused:
The form calls 2 sub-forms and is read only.
 
gpurger said:
I am trying to create a close form command button.

Dispense with the wizard.

The only code encessary is:

  • if you want to close the current form:

    Code:
    DoCmd.Close acForm, Me.Name
  • if you want to close another open form:

    Code:
    DoCmd.Close acForm, "MyForm"
    where MyForm is the name of the form you want to close.

Either of these in the OnCLick() event of a command button (via the Code Builder) will suffice
 
Tried your code as shown
DoCmd.Close acForm, Me.FrmEmployees
Still got the same error.
There is something stopping the buttons on this form. Everything works on the other forms.
Dbase attached.

Cheers
 
gpurger said:
Tried your code as shown
DoCmd.Close acForm, Me.FrmEmployees

That's not what I showed at all.

The first I showed was:

Code:
DoCmd.Close acForm, Me.Name

The Me refers to the current form and the name is the form's Name property so, if the form is called frmEmployees, Name already holds this. It should be typed as is.


The second I showed was:

Code:
DoCmd.Close acForm, "MyForm"

The form's name, in this method, should be placed within inverted commas.


So, you can use either:

Code:
DoCmd.Close acForm, Me.Name

[b][size=4]OR[/size][/b]

DoCmd.Close acForm, "frmEmployees"
 
Thanks for that. I have tried both ways and it still will not work. Is there a property that may affect the code execution.
I am totally lost.
 
The only problem I can see with the example you uploaded is that you are attempting to resize the screen when the form loads based on the screen resolution but the relevant module is not present - once the lines pertaining to some sort of resizing Class have been removed your problem goes away.

Did you just copy the code from somewhere?
 
I was playing with some code.
Thank you for your time and patiance
 

Users who are viewing this thread

Back
Top Bottom