general function to add record, assign to command button
---
Hi Ghost,
put this procedure in a general module:
'------------------------------------ RecordNew
Function RecordNew()
'example useage: OnClick event of a New Record command button
' = RecordNew()
On Error GoTo RecordNew_error
'if there have been changes to the current record, save them
If Screen.ActiveForm.Dirty Then Screen.ActiveForm.Dirty = False
DoCmd.RunCommand acCmdRecordsGoToNew
Exit Function
RecordNew_error:
If Err.Number = 2046 Then
'You are already on a new record
Exit Function
End If
MsgBox Err.Number & " " & Err.Description, , "Cannot go to a new
record right now"
End Function
'~~~~~~~~~~~~~
How to Create a General Module
1. from the database window, click on the Module tab
2. click on the NEW command button
3. type (or paste) the code in
once the code is in the module sheet, do
Debug,Compile from the menu
if there are no syntax/reference errors, nothing will appear to happen
-- this is good
~~~~~~~~~~~~~~~~~~~~~~~~~
How to assign a general function to a command button:
go to the design view of your form
make a command button (Cancel the wizard)
turn on the properties window
(from the menu --> View, Properties
OR
R-click and choose Properties from the shortcut menu)
if the command button is not still selected, click on it
click on the All tab in the properties window
Name --> cmdAddRecord
click on the Events tab
in the Click event -->
=RecordNew()
Warm Regards,
Crystal
*

have an awesome day

*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*