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!

Closing a form? 1

Status
Not open for further replies.

actionbasti

Programmer
Aug 10, 2005
8
US
Hi,

I am really new to adp and access.

I am trying to open a form based on a listbox selected item. That works great but i cannot close the origin form. This code gives me an error. The close command just closes everything and brings the following error message:
The expression you entered refers to an object that is closed or doesn't exist.

CODE:

Private Sub btnNewProject_Click()
On Error GoTo Err_btnNewProject_Click
DoCmd.Close

Dim stDocName As String
Dim stLinkCriteria As String

gCurrentProjectID = List3.ItemData(List3.ListIndex)
stLinkCriteria = "[project_id]=" & gCurrentProjectID
stDocName = "frmNewProject"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnNewProject_Click:
Exit Sub

Err_btnNewProject_Click:
MsgBox Err.Description
Resume Exit_btnNewProject_Click

End Sub


I have the same code with the stLinkCriteria as an empty string, and there it works great, when i open the form, the original form closes. but here it doesnt work... why?
 
actionbasti,

You don't want to close the form that holds the list box until you've at least set the gCurrentProjectID variable, as this needs to reference the list box to get it's value. This is where the error is voming from. Try moving the DoCmd.Close line to the bottom of the routine. To ensure that you're then closing the correct form, explicitly name the form (or use "Me.Name") as one of the parameters of the DoCmd.Close function -

e.g. DoCmd.Close acForm, Me.Name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top