H
Hywel
Guest
On my forms i have cmd buttons for next, previous, last and first, but these are disabled as appropriate by the following code. (thanks mile-o-phile)
But, when i add new record, i get a Run-time error 3021, no current record. and when i debug, it highlights:
recClone.Bookmark = Me.Bookmark
The code for disabling and adding a record are below:
Private Sub Form_Current()
Dim recClone As Recordset
Dim intNewRecord As Integer
' Make a clone of the recordset underlying the form so we can move
' around that without affecting the form's recordset
Set recClone = Me.RecordsetClone
' If this is a new record then disable the <NEXT> button and enable
' the <PREV> button and then exit the procedure
intNewRecord = IsNull(Me.[IAAF Number])
If intNewRecord Then
cmdprevrec.Enabled = True
cmdnextrec.Enabled = False
cmdlastrec.Enabled = False
Exit Sub
End If
' If we reach here, we know we are not in a new record so need to
' see if there are no records. If this is the case then we must
' disable both the <PREV> and <NEXT> buttons.
If recClone.RecordCount = 0 Then
cmdprevrec.Enabled = False
cmdnextrec.Enabled = False
cmdfirstrec.Enabled = False
cmdlastrec.Enabled = False
Else
' Synchronise the current pointer in the two recordsets
recClone.Bookmark = Me.Bookmark
' If there are records, see if we are on the first record.
' If so, we should disable the <PREV> buttons.
recClone.MovePrevious
cmdprevrec.Enabled = Not (recClone.BOF)
cmdfirstrec.Enabled = Not (recClone.BOF)
recClone.MoveNext
' And then check whether we are on the last record.
' If so, we should disable the <NEXT> buttons.
recClone.MoveNext
cmdnextrec.Enabled = Not (recClone.EOF)
cmdlastrec.Enabled = Not (recClone.EOF)
recClone.MovePrevious
End If
' Finally, we close the cloned recordset
recClone.Close
End Sub
For the adding a new record i'm using this code
Private Sub cmdaddrec_Click()
On Error GoTo Err_cmdaddrec_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdaddrec_Click:
Exit Sub
Err_cmdaddrec_Click:
MsgBox Err.Description
Resume Exit_cmdaddrec_Click
End Sub
Any suggestions for fixing it would be appreciated,
Hywel
But, when i add new record, i get a Run-time error 3021, no current record. and when i debug, it highlights:
recClone.Bookmark = Me.Bookmark
The code for disabling and adding a record are below:
Private Sub Form_Current()
Dim recClone As Recordset
Dim intNewRecord As Integer
' Make a clone of the recordset underlying the form so we can move
' around that without affecting the form's recordset
Set recClone = Me.RecordsetClone
' If this is a new record then disable the <NEXT> button and enable
' the <PREV> button and then exit the procedure
intNewRecord = IsNull(Me.[IAAF Number])
If intNewRecord Then
cmdprevrec.Enabled = True
cmdnextrec.Enabled = False
cmdlastrec.Enabled = False
Exit Sub
End If
' If we reach here, we know we are not in a new record so need to
' see if there are no records. If this is the case then we must
' disable both the <PREV> and <NEXT> buttons.
If recClone.RecordCount = 0 Then
cmdprevrec.Enabled = False
cmdnextrec.Enabled = False
cmdfirstrec.Enabled = False
cmdlastrec.Enabled = False
Else
' Synchronise the current pointer in the two recordsets
recClone.Bookmark = Me.Bookmark
' If there are records, see if we are on the first record.
' If so, we should disable the <PREV> buttons.
recClone.MovePrevious
cmdprevrec.Enabled = Not (recClone.BOF)
cmdfirstrec.Enabled = Not (recClone.BOF)
recClone.MoveNext
' And then check whether we are on the last record.
' If so, we should disable the <NEXT> buttons.
recClone.MoveNext
cmdnextrec.Enabled = Not (recClone.EOF)
cmdlastrec.Enabled = Not (recClone.EOF)
recClone.MovePrevious
End If
' Finally, we close the cloned recordset
recClone.Close
End Sub
For the adding a new record i'm using this code
Private Sub cmdaddrec_Click()
On Error GoTo Err_cmdaddrec_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdaddrec_Click:
Exit Sub
Err_cmdaddrec_Click:
MsgBox Err.Description
Resume Exit_cmdaddrec_Click
End Sub
Any suggestions for fixing it would be appreciated,
Hywel