Open a form with a blank record and view existing records

S

Sara P.

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.
 
A

Allen Browne

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

Sara P.

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.
 
B

BB

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?
 
J

John W. Vinson

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 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.
 
B

BB

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

John F.

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
 
J

John F.

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

John F. said:
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

Allen Browne said:
Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top