I forgot to mention that the code I presented below was written using the
Categories form in the sample Northwind database. You will need to modify
this line of code:
If IsNull(Me.CategoryID) Then
in the Private Sub Form_Current() procedure, so that it references the
applicable primary key field name.
Tom
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
:
To add some to Ofer's reply, you will want to convert all macros (except
Autoexec and Autokeys) to the equivalent VBA code, and make sure that each
procedure includes error handling. Unhandled errors in run-time applications
will cause the types of crash that you described.
Here is some code that you can try, for (5) command buttons on a form named
cmdFirst, cmdPrevious, cmdNext, cmdLast and cmdAdd
Option Compare Database
Option Explicit
Private Sub Form_Current()
On Error GoTo ProcError
If IsNull(Me.CategoryID) Then
cmdPrevious.SetFocus
cmdNext.Enabled = False
Else
cmdNext.Enabled = True
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
End If
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Form_Current..."
Resume ExitProc
End Sub
Private Sub cmdPrevious_Click()
On Error GoTo ProcError
DoCmd.GoToRecord , , acPrevious
ExitProc:
Exit Sub
ProcError:
Select Case Err.Number
Case 2105
Me.cmdNext.SetFocus
Me.cmdPrevious.Enabled = False
Me.cmdFirst.Enabled = False
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdPrevious_Click..."
End Select
Resume ExitProc
End Sub
Private Sub cmdNext_Click()
On Error GoTo ProcError
DoCmd.GoToRecord , , acNext
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdNext_Click..."
Resume ExitProc
End Sub
Private Sub cmdFirst_Click()
On Error GoTo Err_cmdFirst_Click
DoCmd.GoToRecord , , acFirst
cmdPrevious.Enabled = False
cmdNext.SetFocus
cmdFirst.Enabled = False
Exit_cmdFirst_Click:
Exit Sub
Err_cmdFirst_Click:
MsgBox Err.Description
Resume Exit_cmdFirst_Click
End Sub
Private Sub cmdLast_Click()
On Error GoTo ProcError
DoCmd.GoToRecord , , acLast
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdLast_Click..."
Resume ExitProc
End Sub
Private Sub cmdAdd_Click()
On Error GoTo ProcError
DoCmd.GoToRecord , , acNewRec
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdAdd_Click..."
Resume ExitProc
End Sub
Tom
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
:
On the Onclick event of the form, use code instead of Macro
Private Sub ButtonName_Click()
On Error GoTo Err_ButtonName_Click
DoCmd.GoToRecord , , acPrevious
Exit_ButtonName_Click:
Exit Sub
Err_ButtonName_Click:
MsgBox Err.Description
Resume Exit_ButtonName_Click
End Sub
--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck
__________________________________________
:
I've created a button that takes me to the "previous record" in a MS Runtime
application. If I happen to be at the beginning of the record list, the
program will just quit ( in Access, it will give you an error msg- in
Runtime, the program will quit) Any suggestions on how to limit the "previous
record" macro to go as far back as the first record and no further?