Do a Cmd & then Close

N

Nick T

Hi,
I have a cmd button for which i have the following code behind. Im using
this button to open a form, however, when this button is clicked, i want the
form on which this button is located to close. Where in my code could i put
a DoCmd.close function, or somthing simular to carry out the same function?
In summary, in one click, i want to open one form & close another(?)

My code behind my Cmd button is:


Private Sub Command2_Click()
On Error GoTo Err_Command2_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form1"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Forms.Form1.FillLocation = Forms.Form2.FillLocation
Forms.Forms1.ProductDescription = Forms.Form2.ProductDescription


Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub


This code is behind my cmd button "Command2". It carrys out its function
well, however i also want it to close the form that "Command2" is on when it
is clicked.

I hope iv not confused my explanation, however any help appreciated.

Many thanks
 
C

Clifford Bass

Hi Nick,

Add this line just before the Exit_Command_2_Click: line:

DoCmd.Close acForm, Me.Name

Clifford Bass
 
N

Nick T

Excellent,

Just what i needed.

Many thanks


Clifford Bass said:
Hi Nick,

Add this line just before the Exit_Command_2_Click: line:

DoCmd.Close acForm, Me.Name

Clifford Bass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

open in datasheet view 1
Open a form and close one 1
Problem with query criteria 6
transfer a field using button 1
E-mail Code 2
compile error 5
Query based on dropdown selection 2
Database security 1

Top