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 / April 2005

Tip: Looking for answers? Try searching our database.

Can't open new form AND go to new record?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pat Dools - 09 Apr 2005 15:09 GMT
Hello,

I have the following code behind a Command Button that is supposed to:

1)  Save the current record
2)  Open a different form
3)  Allow me to enter a New record on the form opened in #2

Here's the code:

Private Sub CommandGemD08_Click()
DoCmd.Save acForm, "fCycDoseVitalGemCyc01D01"
DoCmd.OpenForm "fCycDoseVitalGemCyc02D01", acNormal
DoCmd.GoToRecord acDataForm, "fCycDoseVitalGemCyc02D01", acNewRec
DoCmd.Close acForm, "fCycDoseVitalGemCyc01D01"
End Sub

In debugging this code, it clearly skips over the line where a New Record is
brought up for the new Form ("fCycDoseVitalGemCyc02D01"):

DoCmd.GoToRecord acDataForm, "fCycDoseVitalGemCyc02D01", acNewRec

It does open the form I want it to open, but I have code that checks if you
are opening a new record or not on every Form's 'OnCurrent' event:

Private Sub Form_Current()
If Me.NewRecord Then
Call SetAutoValues(Me)
Else
Call LockControls(Me)
End If
End Sub

If it's new, 'SetAutoValues' automatically fills in some header fields
identifying the current patient record that you are entering (e.g., ID,
initials, etc.).  If it is NOT new, then 'LockControls' locks down all
controls on that record to prevent our data entry people from being able to
go back and edit records that have already been entered.  So, by skipping
this line:

DoCmd.GoToRecord acDataForm, "fCycDoseVitalGemCyc02D01", acNewRec

the form that is opened is not treated as a New Record, and thus all
controls on the form (Text Boxes, Combo Boxes) used to enter data into the
underlying table are 'locked'.  Why is it skipping the 'DoCmd...' code that
creates a New Record and how can I adjust it to have a New Record brought up?

Thanks.
Signature

Pat Dools

Paul Overway - 09 Apr 2005 15:18 GMT
If you step through the code, you'll find that fCycDoseVitalGemCyc02D01 is
being opened...and then closed.  You should try this instead:

DoCmd.Save acForm, "fCycDoseVitalGemCyc01D01"
DoCmd.OpenForm "fCycDoseVitalGemCyc02D01", acNormal, , , acFormAdd, acDialog

Signature

Paul Overway
Logico Solutions
http://www.logico-solutions.com

> Hello,
>
[quoted text clipped - 49 lines]
>
> Thanks.
Pat Dools - 09 Apr 2005 18:22 GMT
Thanks, Paul!

> If you step through the code, you'll find that fCycDoseVitalGemCyc02D01 is
> being opened...and then closed.  You should try this instead:
[quoted text clipped - 55 lines]
> >
> > Thanks.
Dan Artuso - 09 Apr 2005 15:24 GMT
Hi,
Surely when you step through the code it tries to execute that line, no?
One thing you should be aware of, this line:
DoCmd.Save acForm, "fCycDoseVitalGemCyc01D01"
*does not* save the current record, it is meant to save any design changes made to the form.

If this code is executing within the form in question, you can use:
Me.Dirty  = False

--
HTH
Dan Artuso, Access MVP

> Hello,
>
[quoted text clipped - 46 lines]
> --
> Pat Dools
Pat Dools - 09 Apr 2005 15:45 GMT
Hi Dan,

Thank you for the response!  One question, is it necessary to perform a
'Save' operation on the record (in looking at the code now, I realize what
you're saying about Saving Design changes on the Form itself) just entered
into the active form-- or is it a 'Best Practice', at least?  Or is it
essentially unnecessary code as the record automatically saves when the form
is closed?

Thanks again.

> Hi,
> Surely when you step through the code it tries to execute that line, no?
[quoted text clipped - 59 lines]
> > --
> > Pat Dools
Dan Artuso - 09 Apr 2005 16:58 GMT
Hi,
If you're closing the form a then the record will be saved anyway, but it won't hurt to explicitly
save it.

--
HTH
Dan Artuso, Access MVP

> Hi Dan,
>
[quoted text clipped - 70 lines]
> > > --
> > > Pat Dools
 
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.