Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

going from form to form

Status
Not open for further replies.

Daya100

Programmer
Jan 11, 2002
21
US
I have a database and there are about 10 different forms the user goes through to enter information. Right now I have command buttons on each form that the user clicks on to go to another form - and whatever record they are on in the first form - it finds it on the other form. The code also has it close the previous form they were on. The problem is that every time I have to add a new form or delete a form - I have to change the command buttons on 9 forms. I tried just using a toolbar with all of the forms on it but I don't know how to find the same record and close the previous form they were on. There must be a simple way to do this. Help please! Thanks!
 
This will work good. Do the following on your first form:

==========
On the button that closes the form

1) Put the following line of code (change the red part to the name of your button):

Call HandleForms(Me.cmdNextForm.Tag)

2) Put a 1 in the "Tag" property of the button
==========

Now do the same thing on each form, giving it a different tag number. It doesn't matter if the Tag numbers are in the same order as the forms have to open, just so long as they are all different.

Next, put the following code in a module:

============================================
Public Sub HandleForms(frmNumber As Integer)
Select Case frmNumber
Case 1
DoCmd.OpenForm "Form2"
DoCmd.CLOSE acForm, "Form1"
Case 2
DoCmd.OpenForm "Form3"
DoCmd.CLOSE acForm, "Form2"
Case 3
DoCmd.OpenForm "Form4"
DoCmd.CLOSE acForm, "Form3"
Case 4
DoCmd.CLOSE acForm, "Form4"
End Select
End Sub
============================================

If you add a form, simply give the button on the new form, the next tag number, and add one case to the select case (again, it doesn't have to be in the same order as the forms open, as you handle what form opens and closes in the sub routine).

Now if you edit forms, the only place you have to change any code is in this module, you never have to touch the button code again, unless of course you want to put other code there.


Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Let me make a correction, or actually a simplification. Put the tag number in the "Tag" property of the form, not the button. Then Every button would have the following line of code:

Call HandleForms(Me.Tag)

This way you don't have to worry about the button names. Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top