Open a form with a blank record and view existing records

Open a form with a blank record and view existing records

Post by U2FyYSBQL » Sat, 24 Feb 2007 06:47:16


I have been trying for days now to get a blank record to appear upon opening
a form, and also to be able to view existing records. I have succeeded in
the blank record by using the DoCmd.GoToRecord,,acNewRec but when I do that I
lose access to all the existing records which I don't want! Someone please
help.
 
 
 

Open a form with a blank record and view existing records

Post by Allen Brow » Sat, 24 Feb 2007 09:18:20

Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://www.yqcomputer.com/
Reply to group, rather than allenbrowne at mvps dot org.

 
 
 

Open a form with a blank record and view existing records

Post by U2FyYSBQL » Sun, 25 Feb 2007 00:28:35

Thank you, Thank you, Thank you! That worked perfectly now I can stop banging
my head against the wall.
Once again much appreciated
Sara P.
 
 
 

Open a form with a blank record and view existing records

Post by QkI » Thu, 28 Feb 2008 13:51:00

I am new at this stuff. Where do i paste this information and is this only
for a sub form or is it for any form?
 
 
 

Open a form with a blank record and view existing records

Post by John W. Vi » Thu, 28 Feb 2008 15:04:41


Open the form in design view. View its Properties; on the Events tab pick the
Load property. Click the ... icon next to it and choose "Code Builder". Copy
and paste the code between the Private Sub... End Sub lines that Access will
give you free of charge.

For a Subform this might not work as desired (i.e. on navigating between
records) but give it a try.
--
John W. Vinson [MVP]
 
 
 

Open a form with a blank record and view existing records

Post by QkI » Fri, 29 Feb 2008 04:19:04

Thank You so much! That worked. I wonder why they don't have that as a
property for forms.
 
 
 

Open a form with a blank record and view existing records

Post by Sm9obiBGL » Tue, 23 Sep 2008 15:26:01

Hi:
I have a master form, 'PATIENTS' from which I open a linked form 'SERVICES'
using a button with OpenForm using a WHERE filter:

Private Sub btnAddServices_Click()
Dim openCriteria As String

openCriteria = "[RecNum]= " & Me.[RecNum] & "AND [Admitdate] = " & "#" &
Me.[Admitdate] & "#"

DoCmd.OpenForm "SERVICES", , , openCriteria
End Sub

This works fine and opens the SERVICES form with the correct records showing.

However, if there are no records to show, I'd like to open 'SERVICES' on a
new, empty record. I tried adding the following to the SERVICES' Load event:
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
but SERVICES then opens on a new record with the default values for 'RecNum'
and 'Admitdate' rather than the values visible on the calling form,
'PATIENTS'. How do I ensure that the new record has the non-default values
entered when 'SERVICES' opens?

Thank you.
johno
 
 
 

Open a form with a blank record and view existing records

Post by Sm9obiBGL » Wed, 24 Sep 2008 15:57:02

Figured it out!

Private Sub btnAddServices_Click()
Dim openCriteria As String

openCriteria = "[RecNum]= " & Me.[RecNum] & "AND [Admitdate] = " & "#" &
Me.[Admitdate] & "#"

DoCmd.OpenForm "SERVICES", , , openCriteria
With Forms("SERVICES")
If .NewRecord Then
.[RecNum] = Me.RecNum
.[Admitdate] = Me.Admitdate

End If
End With

End Sub