|
Question : Hard question:Tab Control Pages;To many command buttons!!
|
|
Question:
WHAT I NEED: Three(preferred) command buttons that will process the same command to whatever TabCntrl Page has the focus. These Three Command buttons will go in the upper portion of the form. CURRENT SCENARIO: One form called frmCrib21 BOUND TO A TABLE CALLED "tblGibase"
Two TabCntrls; One in the upper portion of the form. TabCTL0 One in the lower portion of the form. TabCTL131
In TabCTL131: I have 7 pages. On each page I have several combo boxes that the user picks. These combo boxes range from 7-25 combo boxes depending on which page you are in. These comboboxes have a Row Source(SQL) NOT A control source. I also have two unbound text boxes(ON EVERY PAGE) text1= "Preview Modifiers" text2= "Preview Description"
In TabCTL0: I have a bound textbox called "FINALDESCRIPTION" This is where I want the NEW COMMAND BUTTONS!!!!!!!!!!!
I USUALLY have 5 command buttons on each page,BUT sometimes I only have Three. I'am going to gave an example of 2PAGES. The 1st page with 5 command command buttons(with code) The 2nd page with 3 command buttons.(with code) (preferred scenario) EXAMPLE 1: TabCTL131(page1) Captions Value Combobox1 "Modifier1" Band Combobox2 "Modifier2" Leather Combobox3 "Other" Black Combobox4 "Sizes" 1/2"x4"
5 Command Buttons WHAT THE COMMAND BUTTONS DO: Command1-"PreviewMod" IT Concatenates Combobox 1 and 2 and puts the result in TEXT1. RESULT IN TEXT1= Band, Leather IMPORTANT!!!! ONLY IN THE FIRST COMMAND BUTTON ON EACH PAGE IT ALWAYS PUTS A COMMA and a SPACE BEHIND ANY VALUE CHOSEN IN COMMAND AFTER PRESSING Command(?) CODE: Private Sub Command1_Click() Me![Text1] = IIf(IsNull(Me!Combo1), "", Me!Combo1 & ",") & " " & IIf(IsNull(Me!Combo2), "", Me!Combo2 & " ") '& IIf(IsNull(Me!Combo3), "", Me!Combo3 & " ") _ '& IIf(IsNull(Me!Combo4), "", Me!Combo4 & " ") Forms!frmCRIB21!Text2.SetFocus End Sub
Command2-"Preview" IT Concantenates Combobox 3 and 4 and puts the result in TEXT2. RESULT TEXT2= Black 1/2"x4" CODE: Private Sub Command821_Click() Me![Text2] = IIf(IsNull(Me!Combo3), "", Me!Combo3 & " ") _ & IIf(IsNull(Me!Combo4), "", Me!Combo4 & " ") Forms!frmCRIB21!Text2.SetFocus End Sub
Command3-"Add2" IT Concatenates TEXT1 AND TEXT2 and reposts the result in TEXT2 RESULT TEXT2= Band, Leather Black 1/2"x4" CODE: Me![Text2] = IIf(IsNull(Me![Text1]), "", Me![Text1] & " ") _ & IIf(IsNull(Me![Text2]), "", Me![Text2] & "") Forms!frmCRIB21!Text2.SetFocus End Sub Command4-"Build1" IT post the value from TEXT2 INTO the upper portion of the form to the BOUNDtextbox called "FINALDESCRIPTION" CODE: Private Sub Command4_Click() On Error GoTo Command4_Click_Err
FINALDESCRIPTION = Text2
DoCmd.RunCommand acCmdSaveRecord Dim RETVALUE As String RETVALUE = msgbox("Record Built and SAVED!", vbInformation) Forms!frmCRIB21!FINALDESCRIPTION.SetFocus Command4_Click_Exit: Exit Sub
Command4_Click_Err: 'MSGBOX Error$ msgbox Err.Description Resume Command4_Click_Exit End Sub
Command5-"Klear" IT clears all of the Comboboxes and text fields. BUT NOT "BOUND TEXTBOXES". CODE: Private Sub Command5_Click() [Combo1] = Null [Combo2] = Null [Combo3] = Null [Combo4] = Null [Text1] = Null [Text2] = Null END SUB
EXAMPLE 2: Text boxes on this page are
Text3-"Preview Description"
TabCTL131(page2) Captions Value Combobox10 "Modifier1" Sealant Combobox11 "Modifier2" Tube Combobox12 "Modifier3" Bonded Combobox13 "OtherStuff" Red Combobox14 "SizeAll" 5oz.
3 Command Buttons WHAT THE COMMAND BUTTONS DO: Command8-"PreviewMod" IT Concantenates Combobox 10,11 and 12 13 and 14 and puts the result in TEXT3. RESULT TEXT3= Sealant, Tube Bonded Red 5oz. CODE: Private Sub Command8_Click() ' DATA FOR PREVIEWMOD COMMAND Me![Text3] = IIf(IsNull(Me!Combo10), "", Me!Combo10 & ",") & " " _ & IIf(IsNull(Me!Combo11), "", Me!Combo11 & " ") _ & IIf(IsNull(Me!Combo12), "", Me!Combo12 & " ") _ & IIf(IsNull(Me!Combo13), "", Me!Combo13 & " ") _ & IIf(IsNull(Me!Combo14), "", Me!Combo14 & " ") Forms!frmcrib21!Text3.SetFocus End Sub
Command9-"Build1" IT post the value from TEXT3 INTO the upper portion of the form to the BOUNDtextbox called "FINALDESCRIPTION" CODE: Private Sub Command9_Click() On Error GoTo Command9_Click_Err
FINALDESCRIPTION = Text3
DoCmd.RunCommand acCmdSaveRecord Dim RETVALUE As String RETVALUE = msgbox("Record Built and SAVED!", vbInformation) Forms!frmCRIB21!FINALDESCRIPTION.SetFocus Command9_Click_Exit: Exit Sub
Command9_Click_Err: 'MSGBOX Error$ msgbox Err.Description Resume Command9_Click_Exit End Sub
Command10-"Klear" IT clears all of the Comboboxes and text fields. BUT NOT "BOUND TEXTBOXES". CODE: Private Sub Command10_Click() [Combo10] = Null [Combo11] = Null [Combo12] = Null [Combo13] = Null [combo14] = Null [Text3] = Null END SUB
WHAT I WOULD LIKE TO SEE HAPPEN: I would like to reduce the command buttons to THREE.!!!!!! THESE THREE COMMAND BUTTONS IN THE UPPER PORTION OF THE FORM. EXAMPLE 2 IS THE BEST SCENARIO. I NEED EXAMPLE 1 FOR VARIOUS REASONS BUT I'am WILLING TO GET RID OF FIVE BUTTONS.
AS YOU CAN SEE IF I ADD MORE PAGES AND PERFORM THE SAME ROUTINES I'am ending up with LOTS of command buttons basically doing the same thing. Except on different pages. The only thing different is the names of the comboboxes and textboxes and command buttons have different references and the number of command buttons per page. WOW! Alot to absorb ALOT OF POINTS! AWARD WILL GO TO CODE THAT WORKS!!! I HAVE REVIEWED THIS QUESTI0N OVER AND OVER. IF YOU SEE AN ERROR LET ME KNOW. Good Luck fordraiders
|
|
Answer : Hard question:Tab Control Pages;To many command buttons!!
|
|
I am not quite sure what you expect but I guess that a demonstration of how this should be done is good enough?
1) You have probably noticed by now, the need for proper names on controls, buttons etc. so I am not going to talk about that.
2) I think it should be possible to combine some of your tables into common tables, but it would involve making more general field names and change all your forms so it is better left for future applications.
3) I tried to make some kind of general function that would do the job, provided with proper names on the controls on each tab, but since each tab has its own set of controls without any logical order or number (from the computers point of view) this failed.
4) The solution that I have tried to implement is as follows; 4a) Let the tab show/hide the proper buttons. 4b) Have Select Case on the tab index number decide which code to run. Example below;
Select Case Me!cTabSelection Case 0 ' Abrasive Me![Text817] = IIf(IsNull(Me![Text179]), "", Me![Text179] & " ") _ & IIf(IsNull(Me![Text817]), "", Me![Text817] & "") Me!Text817.SetFocus Me![Text819] = Len(Me![Text817].Text)
Case 1 ' HVAC Me![Text82] = IIf(IsNull(Me![Text197]), "", Me![Text197] & " ") _ & IIf(IsNull(Me![Text82]), "", Me![Text82] & "") Me!Text82.SetFocus Me![Text80] = Len(Me![Text82].Text) Case 2 ' Autoshop Me![Text554] = IIf(IsNull(Me![Text202]), "", Me![Text202] & " ") _ & IIf(IsNull(Me![Text554]), "", Me![Text554] & "") Me!Text554.SetFocus Me![Text556] = Len(Me![Text554].Text)
As you can see I have just copied the from the Add button on each tab and pasted it into the corresponding Case. You can find the number by (in design) pressing the tab and look at the Page Index property.
4c) Removed the button on the pages and made sure that the code bit was also removed.
I have implemented this on form frmOWENS1 for the 3 first tabs to let you see how it is done.
If you want a more "self-configuring" method I am afraid that you will have to come up with some clever naming convention, and I think that it will not be worth the effort.
Some more comments: I) If possible you should use code instead of macros. I only use macro for AutoKeys, AutoExec and routines that need to be run from the database container (during development). Macros have no error trapping possibility and will crash your application if they are executed from runtime versions of Access or from MDE-compiled applications.
II) The above mentioned naming of controls and fields on forms.
III) Why do you need the 4 version of the form. Are they really that different ?
IV) The forms looks nice, but perhaps a bit confusing at first glance. But when dealing with so much info, it is hard to not get this impression.
I will post you the update so you can have a look at it. Please let me know if you need details. Notice that I have renamed the tab control.
|
|
|
|