How to determine the latest record on a form

  • Thread starter Thread starter rene66
  • Start date Start date
R

rene66

Hi all,

I have a form with some custom navigation buttons like goto next
record, previous record, most current record, etc. There is also a
button which creates a new record. Pressing this button adds a new
record and fills some textboxes on the form with data.

Here's the problem:

Users should use this "New record" button to add a new record, and not
the "Next record" button which renders a blank, new record where their
is no data in the textboxes. Is there any way to disable the "Next
record" when the most current record is displayed??

I hope you all know what I maen...

Thnx,

René
 
Hi Rene

The data will be in the text boxes will always be there if you have set this
property (on-load, on-open, etc, etc) to perform this function.

To open a "new record" use the acNewRec command


Private Sub ButtonName_Click()
On Error GoTo Err_ButtonName_Click
DoCmd.GoToRecord , , acNewRec
Exit_ButtonName_Click:
Exit Sub
End Sub


Hope this helps
 
If Me.RecordsetClone.RecordCount <Me.CurrentRecord Then
DoCmd.GoToRecord , , acNext
End If
 
Hi,

Thnx for the replies,

But I have a button which creates a new record...works fine. The
navigationbuttons I created also work fine. What I want is that the
"Next" button will be disbabled ones the most recent record is shown in
the form.

René
 
Hi Rene

I may be wrong but I don't think you need to do anything.

If you form is based on a query/table with the primary key set to
auto-number then after a "new"record is created and you press the "next
record" button it will not work as there isn't a "next" record.

I may have misunderstood. If I have can you give a bit more detail.
 
Wayne,

Yep, you're right...

But the primary-key isn't auto-number. The primarykey is a combination
of year-month-and a following number. It is created by pressing the
"New" button I made. This "new" button also fills some other textboxes.

When the database opens it opens a form showing the most recent record.
Disabling the "Next" button on database startup is fairly easy, but
what if a user browses through the records with the "Previous" button
and after a while the "Next" button and arrives at the most recent
record. Another push at the "Next" button creates a new record but
without the info which is required.

The "Next" button should be disabled ones the most recent record is
shown on the form

René
 
Give this a try - on-open

If Me.NewRecord Then
Me!NextButton.Enabled = False
Else
Me!NextButton.Enabled = True
End If
 
sounds like you have code running behind the "New" button, which moves the
focus to the new record on the form, and then sets the value of certain
fields in the new record, correct?

instead of putting that "set value" code on your "New" button, try adding it
to the *form's* Current event, as

If Me.NewRecord Then
' put here the "set value" code
End If

so as the user moves from one record to another (regardless of how s/he does
it), the system checks to see if the current record is a "new" record. if it
is, and ONLY if it is, then the code run which sets the field values you
need for a new record.

hth


Wayne,

Yep, you're right...

But the primary-key isn't auto-number. The primarykey is a combination
of year-month-and a following number. It is created by pressing the
"New" button I made. This "new" button also fills some other textboxes.

When the database opens it opens a form showing the most recent record.
Disabling the "Next" button on database startup is fairly easy, but
what if a user browses through the records with the "Previous" button
and after a while the "Next" button and arrives at the most recent
record. Another push at the "Next" button creates a new record but
without the info which is required.

The "Next" button should be disabled ones the most recent record is
shown on the form

René
 
Hi,

Thanx everybody for the replies, but I think I solved it (somewhat...)
Not exactly what I wanted but this is good enough...

Dim intnewrec As Integer
Dim msg As String
Dim answer As Integer

intnewrec = Form.NewRecord
msg = "Add a new record?"

If intnewrec = True Then
answer = MsgBox(msg, vbQuestion + vbYesNo, "New record ?")
If answer = vbYes Then
Datum = Date
License = Format([Datum], "yyyy") & "-" & Format([Datum],
"mm") & "-" & [Vergunning]
WOnumber.SetFocus
Else
DoCmd.GoToRecord , , acLast

End If
End If

I think this is more or less like Tina suggested. Some parts in the
code are dutch ;-)
Thnx...

René
 
Back
Top