11. oktober 2005 - 12:21Der er
12 kommentarer og 1 løsning
Stop if last record
In forms I have buttons for going to previous and next record. When standing in the last record and clicking next, I do not want to go to new record. In the recordset there is the field Nr with fieldtype Count. I have tryed with: If IsNull(DLookup("[Nr]", "Tablename", "[Nr] = Forms!Formname!Nr + 1")) Then Beep msg "This is the last record!", vbCritical, "Last record!" Exit Sub End If but this only works if no records has been deleted. If standing in record 31 and record 32 has been deleted, the terms are met even if there are more records than 32. What code can I use for my button to prevent going beyond the last record? Please help!
Eller denne, jeg kalder på frm's onCurrent. Den kræver: Knap frem, knap tilbage, knap gå-til-sidste, knap gå-til-første, label til visning af nummer på valgt post.
Dim strRecordCount As String
cmdNew.Enabled = Me.AllowAdditions
'Ved ingen poster If Me.RecordsetClone.RecordCount = 0 Then cmdFirst.Enabled = False cmdNext.Enabled = False cmdPrevious.Enabled = False cmdLast.Enabled = False cmdDelete.Enabled = True lblPostNr.Caption = "<Ingen data>" Exit Sub ElseIf Me.NewRecord Then cmdFirst.Enabled = True cmdPrevious.Enabled = True cmdNext.Enabled = False cmdLast.Enabled = False cmdNew.Enabled = True cmdDelete.Enabled = True lblPostNr.Caption = "<Ny post>" lblPostNr.FontBold = False Exit Sub
'Next, we must see if we are on the first record 'If so, we should disable the <Previous> button Me.RecordsetClone.MovePrevious cmdFirst.Enabled = Not (Me.RecordsetClone.BOF) cmdPrevious.Enabled = Not (Me.RecordsetClone.BOF) Me.RecordsetClone.MoveNext
'And then check whether we are on the last record 'If so, we should disable the <Next> button Me.RecordsetClone.MoveNext cmdNext.Enabled = Not (Me.RecordsetClone.EOF) cmdLast.Enabled = Not (Me.RecordsetClone.EOF) Me.RecordsetClone.MovePrevious end if
I thank You all for intrest in my question, but I want to keep things as simple as possible. After thinking it throu i come upp with the following solution: If DCount("Nr", "Table", "Nr >Forms!Formname!Nr") = 0 Then msg "Detta är sista posten", vbCritical, "Sista posten!" Else DoCmd.GoToRecord , , acNext End If No record can have a higher nbr than the last record. I tryed different ways to use EOF but for some reason it did'nt work. Thanks again.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.