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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close form code

Status
Not open for further replies.

celie

Technical User
Sep 16, 2003
5
GB
Hi

Ive set up a command button (suppliernbutton) to open up a new form. I would like to also set up an event on this suppliernbutton click to close the current form.

I know that the close form code is DoCmd.Close but how would I use this in the click event code below to close the current form?

Im new to VB programming so please help!!

Private Sub suppliernbutton_Click()
On Error GoTo Err_suppliernbutton_Click

Dim stDocName As String
Dim stLinkCriteria As String

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

Exit_suppliernbutton_Click:
Exit Sub

Err_suppliernbutton_Click:
MsgBox Err.Description
Resume Exit_suppliernbutton_Click


End Sub
 
Hi


stDocName = "SupplierForm1"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm,"frmFormName"

Where "frmFormName" is the name of teh form containing the button which opens "SupplierForm1"

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
In your code you have these two lines.

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

Just add this after them.


DoCmd.Close acForm, Me.Name

That should close the open form just after your new form has opened and taken focus.

Hope this is some help. :)
 
An alternative is placing:

DoCmd.Close

BEFORE

stDocName = "SupplierForm1"
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Yes, thanks Ive tried this code and got it to work on my database.

I've decided, though, to use a "refresh" command button on my original form rather than close it to update the data in its combobox. Ive used the code - Me![Supplier].Requery

Ideally I would like to refresh the supplier data in the combobox of the orignal form when the user closes the supplier form but the supplier form does not recognise the combobox "Supplier" field in the original form.

I hope this makes sense and any more ideas on this would be much appreciated!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top