How can I close a form?

Javelin

The Backpacker
Local time
Today, 02:38
Joined
Mar 14, 2003
Messages
12
Can someone please help?

I have a database where the users can view all the records, via a form, in read-only format. Should the user wish to change any details at all on a particular record - they are forced to complete an audit trail first.

All this simply means is that at the bottom of each record (form) there is a link to the audit trail - this link was created using the command wizard to select the specific record. This is the code that is produces;

Private Sub Command51_Click()
On Error GoTo Err_Command51_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Amend Risk"

stLinkCriteria = "[Risk No]=" & "'" & Me![Ref No] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close "Audit Testpage"

Exit_Command51_Click:
Exit Sub

Err_Command51_Click:
MsgBox Err.Description
Resume Exit_Command51_Click

End Sub

My problem is that I want the form the user is leaving (i.e. The Audit Testpage) to close once the command link is clicked to open the Amend Risk [form]. What code do I need to enter?

Thanks

Jav

:confused:
 
Is this what you're looking for?

DoCmd.OpenForm "MyNewFormName"
DoCmd.Close acForm, "MyFormName"

Hope this helps,
 
Thanks Peter - that's great.
 
I have tried everything and cannot get my form to close upon opening another. The new form just opens behind the form I want to close. My code is in the "Not In List" event of my Add Records form. The new form is called NotInList. Can anyone see where this is not working? I have it coded so it will keep the current Employee ID upon opening the new form, and that works fine.

Thanks!

Toni




Private Sub DocID_NotInList(NewData As String, Response As Integer)

On Error GoTo Err_NotInList_Click

Dim stDocName As String
stDocName = "NotInList"

If MsgBox("This Document does not exist in the database, would you like to add it?", vbYesNo) = vbYes Then

DoCmd.openform stDocName
Forms!NotInList!EmployeeID = Forms![Add Records]! EmployeeID
DoCmd.Close acForm, "[Add Records]"

Else
DoCmd.Close acForm, "[Add Records]"


End If


Exit_NotInList_Click:
Exit Sub

Err_NotInList_Click:
MsgBox Err.Description
Resume Exit_NotInList_Click



End Sub
 
Take the brackets out of the code: DoCmd.Close acForm, "[Add Records]"

It should be: DoCmd.Close acForm, "Add Records"
 
Thanks for the fast reply-I also had my Add Records form set to Pop up so that's why it stayed on top, but here is what I am getting now:

On not in list event-

My Msg comes up "Document does not exist-Add? Yes, No. When I click Yes, the new form opens on top of the previous and my same Msg comes up again-I click Yes and new Msg-"The Close action was cancelled" comes up. I click OK, the previous form closes and leaves my Not In List form open(which is ultimately what I want).

Thanks again!
 
Got everything to work except that when I save the record in my NotInList form and it closes leaving just my main form open, I click "Close Database" and my original message "Document does not exist-Add?" comes up?
I click yes, then I get the Close action was cancelled" msg again. I have tried click "No" don't add and the record has actually been already saved (I closed and reopended the DB) which is good, but there doesn't seem to be any reason for these messages to come up again. Here is my code for the "NotInList" form:

Private Sub Command42_Click()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "NotInList"



End Sub

Private Sub Command45_Click()
DoCmd.RunCommand acCmdUndo
DoCmd.Close acForm, "NotInList"

End Sub


Private Sub Form_AfterUpdate()
Forms!Employees![Combined Subform].Requery
End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Response = acDataErrContinue
End Sub

Private Sub Form_Load()

DoCmd.Close acForm, "[Add Records]"
DocNumber.SetFocus

End Sub

-----

And here is my code for the "OnNotInList" event of my Add Records form (1st form)
Private Sub DocID_NotInList(NewData As String, Response As Integer)

On Error GoTo Err_NotInList_Click

Dim stDocName As String
stDocName = "NotInList"

If MsgBox("This Document does not exist in the database, would you like to add it?", vbYesNo) = vbYes Then

DoCmd.openform stDocName
Forms!NotInList!EmployeeID = Forms![Add Records]!EmployeeID
Me.Visible = False
'DoCmd.Close acForm, "Add Records"

Else
DoCmd.Close
Response = acDataErrContinue


End If

Exit_NotInList_Click:
Exit Sub

Err_NotInList_Click:
MsgBox Err.Description
Resume Exit_NotInList_Click



End Sub

Any push in the right direction would be much appreciated!!!!

Thanks,

Toni
 

Users who are viewing this thread

Back
Top Bottom