After searching various forums, I haven't been able to resolve my challenge.
I have a module where I store all of my navigation buttons, so I don't have to use Access' default form navigations (next, previous, delete, undo, etc.)
For my current New button, the sub is:
Code:
Sub NewButton()
DoCmd.GoToRecord, , acNewRec
End Sub
Then, wherever I insert an "Add New" button, the OnClick event code is It's simple. It works. I want more.
What I want to be able to do is push some of the other things that I may do into this module, to keep things consistent across my database. For instance, when the user presses the [ADD] button, I want to:
- Unlock and enable the pertinent control (I usually don't want them editing. I'm capturing new instances)
- Change the caption of the "Add" button to "Undo" in case they really don't want to Add
- Go to a new record (as I had before.)
- Set the focus on the pertinent control.
- Reverse everything if the hit the same command to "Undo" or Cancel the Add. (put back the "Add" caption, relock, re-disable.)
What I thought I could do was pass the form and controls to the Sub in the module (which I can), but I can't seem to make use of them.
This is my sub:
Code:
Sub AddNewButton (frm as Form, ctl as Control)
If frm.ctl.Locked = True then
frm.ctl.Locked = False frm.ctl.Enabled = True
frm.cmdAddNew.Caption = "Undo"
DoCmd.GoToRecord , , acNewRec
frm.ctl.SetFocus
Else
frm.Undo
frm.ctl.Locked = True
frm.ctl.Enabled = False
frm.cmdAddNew.Caption = "+ADD"
End If
End Sub
In my forms' modules, I was entering
Code:
Private Sub cmdAddNew_Click()
AddNewButton Me, cboVendor
End Sub
I know I can the pass frm and ctl, because when I
Code:
debug.print frm.name ctl.name
in my database module, I see that what I was expecting to pass to the module Sub is there.
I appreciate your help in this. I'm either doing something incorrectly, trying to do something I shouldn't, or both.