Results 1 to 12 of 12
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Whick Button Control Got me Here?

    A2k (9.0.4402) SR-1

    I have an Add and Edit Button on a Form, how do I store which button which button was pressed, so I can use common code, test the saved button and have it behave accordling to the button pressed?

    Thanks, John Graves

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    The easiest way is to pass the button as a CommandButton object to the routine you're calling from that button's click event. Then you don't need to save anything because all the button's properties are available to the code routine you called.. All you need is something like this:

    Private Sub cmdAdd_Click()
    ButtonClick Me!cmdAdd
    End Sub

    Where ButtonClick is assumed to be the name of the routine you're calling.
    Charlotte

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Hi Charlotte

    I didn

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    I'm the one who misunderstood.

    In the declarations section of your form, create a variable like this:

    Private ButtonClicked As String

    In the Click even of each button, put the name of the button clicked into the variable (i.e., ButtonClicked = "cmdAdd"). Then in the event procedure behind the Cancel button, you simply look to see which button was the last one clicked. Once you've done your Cancel button processing, you will want to reset ButtonClicked to an empty string or even to "cmdCancel" just so you don't hold onto the previous value.
    Charlotte

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Hi Charlotte

    Worked perfect!

    To take it one step further:

    If I have a tabbed form with Tab A, Tab B and Tab C, and the form footer has Add, Edit, etc buttons

    If Tab B has the focus and I click the Edit button to enable Tab B fields, is there a way in the Edit button VBA to determine which Tab had the focus when Edit button was pressed so focus can be returned to the proper Tab?

    Thanks, John

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Use the same technique as for the buttons.
    In the declarations section of your form, create a variable like this:

    Private ActiveTab As String

    In the On open event of the form:
    ActiveTab = Me.TabControl.Pages(Me.TabControl.Value).Name

    In the On Change event of the tabcontrol :
    ActiveTab = Me.TabControl.Pages(Me.TabControl.Value).Name
    Francois

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Are Tab A, B and C tab controls or tab pages? If they're separate controls, use Francois's suggestion. If they're pages on the same tab control, you don't need to do anything but look at the value of the tab control, which will give you the page on top.
    Charlotte

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Hi Charlotte

    Stiill confused on the above post.

    If I have a tabbed form with Tab A, Tab B and Tab C, and the form footer has Add, Edit, etc buttons

    I have one TabCtl0 with three pages indexed 0 - 2

    If Tab B has the focus and I click the Edit button to enable Tab B fields, is there a way in the Edit button VBA to determine which Tab had the focus when Edit button was pressed so focus can be returned to the proper Tab?

    Struggling with syntax to get focus back to correct page.

    Thanks, John

  9. #9
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    If Tab B has the focus when you click the edit button, TabCtl0 will have a value of 1.
    To reset the focus to Tab B set TabCtl0 = 1.
    Francois

  10. #10
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Hi Francois

    I have the following in In the On open event of the form and In the On Change event of the tabcontrol :

    ActiveTab = Me.TabCtl0.Pages(Me.TabCtl0.Value).Name

    I have this behind my Edit button code and it works fine, however, how can I capture the tab number (0-7) instead of the tab name?

    Select Case ActiveTab
    Case "Permit Information"
    TabCtl0 = 0
    Me!dtmReceiveDate.SetFocus
    Case "Notes"
    TabCtl0 = 1
    Me!memConNote.SetFocus
    Case "Applicant/Contractor"
    TabCtl0 = 2
    Me!strApplicant.SetFocus
    Case "Specifics"
    TabCtl0 = 3
    DoCmd.GoToControl "frmBPSpecsSubForm"
    DoCmd.GoToControl "lngSetFrontFootage"
    Case "Approvals"
    TabCtl0 = 4
    DoCmd.GoToControl "frmBPReqApprSubForm"
    DoCmd.GoToControl "lngReqApprCodeID"
    Case "Inspections"
    TabCtl0 = 5
    DoCmd.GoToControl "frmBPReqInspSubForm"
    DoCmd.GoToControl "lngReqInspCodeID"
    Case "Fees"
    TabCtl0 = 6
    DoCmd.GoToControl "frmBPFeesSubForm"
    DoCmd.GoToControl "dtmIssueDate"
    Case "Status"
    TabCtl0 = 7
    DoCmd.GoToControl "frmBPStatusSubForm"
    DoCmd.GoToControl "dtmDate"
    End Select

    Thanks, John

  11. #11
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    You can change the ActiveTab from a string to an integer.
    In the On Open event set:
    ActiveTab = Me.TabCtl0

    Behind the edit :

    ActiveTab = Me.TabCtl0
    Select Case ActiveTab
    Case 0
    Me!dtmReceiveDate.SetFocus
    Case 1
    Me!memConNote.SetFocus
    Case 2
    Me!strApplicant.SetFocus
    Case 3
    DoCmd.GoToControl "frmBPSpecsSubForm"
    DoCmd.GoToControl "lngSetFrontFootage"
    Case 4
    DoCmd.GoToControl "frmBPReqApprSubForm"
    DoCmd.GoToControl "lngReqApprCodeID"
    Case 5
    DoCmd.GoToControl "frmBPReqInspSubForm"
    DoCmd.GoToControl "lngReqInspCodeID"
    Case 6
    DoCmd.GoToControl "frmBPFeesSubForm"
    DoCmd.GoToControl "dtmIssueDate"
    Case 7
    DoCmd.GoToControl "frmBPStatusSubForm"
    DoCmd.GoToControl "dtmDate"
    End Select

    When the edits are done (I suppose with an Save button), activate the tab that was active when the edit button was clicked with
    Me.TabCtl0 = ActiveTab
    Francois

  12. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Whick Button Control Got me Here? ( A2k (9.0.4402) SR-1)

    Hi Francois

    Works great.

    Thanks, John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •