How do I do this.

Geoff Codd

Registered User.
Local time
Today, 17:49
Joined
Mar 6, 2002
Messages
190
I have 3 buttons on my form 1 shows all records,1 goes to the previous record, and 1 goes to the next record. There is about 200 lines of code behind each button as it works out should certain item be enabled or visible. The code is the same for each button. I want to know if there is a way of only using the one set of code and each button accessing it.

Thanks in advance
Geoff
 
Hi Geoff

Is all the code exactly the same apart from the next/previous/show all part? Is all of this code only going to be used on this form (and not for other forms)?

Assumming "Yes" for both then ... create a new Private Sub (call it whatever you like within reason -
Private Sub Enable_Controls)

In this Sub place all the "shared" code. Then in each of the Subs for the command buttons call this code.

e.g.

Call Enable_Controls

So your complete code for the Next Command button (cmdNext) would be ...

---------------------------------------------

Private Sub cmdNext_Click()
' Comments :
' Parameters : -
' Returns : -
' Created : 11/04/2000 Rich Gorvin
' Modified : 16/05/2001 Rich Gorvin
'
' --------------------------------------------------------
On Error GoTo Err_cmdNext_Click


DoCmd.GoToRecord , , acNext
Call Enable_Controls

Exit_cmdNext_Click:
Exit Sub

Err_cmdNext_Click:
MsgBox Err.Description & _
" - (Error No:" & Err.Number & ")"
Resume Exit_cmdNext_Click

End Sub
---------------------------------------------

HTH

Rich

[This message has been edited by Rich@ITTC (edited 03-12-2002).]
 
An approach would be to use the tag property of your controls to differenciate the ones that should be hidden/shown.
Then, loop through your controls using a For Each syntax, test for the tag property in the loop.
Your show/hide code should then need to be written only once in the loop.

Re-post if this is not clear.

Alex

[This message has been edited by Alexandre (edited 03-12-2002).]
 

Users who are viewing this thread

Back
Top Bottom