Re: Custom New...Edit...Save buttons



Ken Mylar wrote:
Thanks for your help! I'm not sure how to go about storing the ID when
I save the record.

Go to the top of the code. Under your Option statemets (I assume you have at least OptionExplicit), enter something like
Dim lngStoreID As Long

In the BeforeUpdate or AfterUpdate event of the form, store the ID. Ex:
lngStoreID = Me.ID

See code comments below. BTW, it assumes your id is numeric long.

I have a bunch of forms that all the same exact
buttons, so I created all my code as a Public Function, so I didn't
have to keep duplicating all the same code. The Save function is shown
below, I hope this can work on a global level because it sounds like
exactly what I need. If not, I may need to take the Save function down
to form level.

Thanks,
Ken
*******************************************************************************
Public Function cmdSave_Click(frm As Form)
On Error GoTo Err_cmdSave_Click

Dim ctl As Control

For Each ctl In frm.Controls
If ctl.Tag = "Unlockable" Then
ctl.Enabled = False
ElseIf ctl.Tag = "AlwaysLocked" Then
ctl.Enabled = False
End If
Next ctl

DoCmd.RunCommand acCmdSaveRecord

frm.cmdFirst.Enabled = True
frm.cmdPrevious.Enabled = True
frm.cmdNext.Enabled = True
frm.cmdLast.Enabled = True
frm.cmdClose.Enabled = True
frm.cmdEdit.Enabled = True
frm.cmdNew.Enabled = True
frm.cmdDelete.Enabled = True
frm.btnUndo.Enabled = False
frm!cmdEdit.SetFocus
frm.cmdSave.Enabled = False
frm.AllowAdditions = False
frm.DataEntry = False

It appears that when you set dataentry to false, it "requery's" the form. In that case, put the code
Dim rst As Recordset
set rst = Me.RecordsetClone
rst.Findfirst "ID = " & lngStoredID
Me.bookmark = rst.Bookmark
rst.close
set rst = Nothing
here.


Exit_cmdSave_Click:
Exit Function

Err_cmdSave_Click:
Call LogError(Err.Number, Err.Description,
"cmdSave_Click()", "modFormNavigation")
Resume Exit_cmdSave_Click
End Function

.


Quantcast