Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / August 2005

Tip: Looking for answers? Try searching our database.

Close a form two ways

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert_L_Ross - 03 Aug 2005 18:26 GMT
Here is my problem...

I am trying to code two ways of closing a form:
 One way cancells the existing record, closes the form and returns to the
previous form.
 The second way closes the form and requeries the previous form.

The basis for this decision is the [date finalized] field on my form.  Here
is the code I'm trying:
   Dim SearchBatchID As String
   
   SearchBatchID = Forms!CurrentAuditStatusIncompleteAudits!BatchID
   
   If Forms!Audits![Date Finalized] Is Null Then
       SendKeys "{ESC}{ESC}", False
       DoCmd.Close acForm, "Audits", acSaveNo
   Else
       DoCmd.Close acForm, "Audits", acSaveNo
       DoCmd.Requery ""
       Me![BatchID].SetFocus
       DoCmd.FindRecord SearchBatchID, , , , False
   End If

Any ideas?
Robert_L_Ross - 03 Aug 2005 18:40 GMT
I found the answer...

In an unrelated post I read that Null is not a valid operator in VBA, that
you need to use the IsNull function, so I re-wrote the code as follows:
Private Sub CloseAudit_Click()

   Dim SearchBatchID As String
   
   SearchBatchID = Forms!CurrentAuditStatusIncompleteAudits!BatchID
   
   If IsNull(Forms!Audits![Date Finalized]) Then
       SendKeys "{ESC}", True
       SendKeys "{ESC}", True
       SendKeys "{ESC}", True
       DoCmd.Close acForm, "Audits", acSaveNo
   Else
       DoCmd.Close acForm, "Audits", acSaveNo
       DoCmd.Requery ""
       DoCmd.GoToControl "BatchID"
       DoCmd.FindRecord SearchBatchID, , , , False
   End If
   
End Sub

I had to modify the SendKeys statement to set Wait to True, otherwise the
form closed so quickly it would inadvertently save the record.

Just out of curiosity, how would I replace the SendKeys statements (who's
purpose is only to make sure the record is cancelled before saving) with
something else?  I've heard that the SendKeys statement is a bad idea in
VB...all I want to do is to cancel the current record before saving so when I
close the form it acts as if the record never existed.

THX!

> Here is my problem...
>
[quoted text clipped - 20 lines]
>
> Any ideas?
Klatuu - 03 Aug 2005 19:11 GMT
   If IsNull(Forms!Audits![Date Finalized]) Then
       Me.Undo
       DoCmd.Close acForm, "Audits", acSaveNo
   Else
       DoCmd.Close acForm, "Audits", acSaveNo
       Me.Requery
       Me!BatchID.SetFocus
       DoCmd.FindRecord SearchBatchID, , , , False
   End If

> Here is my problem...
>
[quoted text clipped - 20 lines]
>
> Any ideas?
Robert_L_Ross - 04 Aug 2005 01:01 GMT
Klatuu,

THX, that works perfect!

>     If IsNull(Forms!Audits![Date Finalized]) Then
>         Me.Undo
[quoted text clipped - 30 lines]
> >
> > Any ideas?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.