Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Red face Unanswered: Using 1 cmd button for 2 task

    How can i use one cmd button to do two different task ?

    I have form "frmReports" which can be open from switchboard and from the mainform. Now when user opens the form "frmReports" from the switchboard and closes the "frmReports" i would like to return back to switchboard. If the same form "frmReports" is open from "frmMain" and when it closes it should return back to "frmMain"

    Is it possible to do this with access ? I was thinking about to have one cmd button on "frmReports" and then have lbl which would chage based on where the form was open but i don't really know how do that.

    Any other suggestion ?
    Skharva

  2. #2
    Join Date
    Oct 2003
    Posts
    66
    You can send information to the form from the form that is calling it using OpenArgs. Then you read the OpenArgs value in the form.open event to determine which form called it. Based on that you determine what action to take.

    Example:
    this code would be executed when you are going to open the other form:

    DoCmd.OpenForm "Form2", , , , , , "CallingForm:Form1"

    this woudl be in the open event for the form being opened
    If Me.OpenArgs = "CallingForm:Form1" then ......
    Last edited by adrkoehler; 05-04-04 at 17:21.

  3. #3
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    There are a few options and they all easy to do.

    What I generally do is have the control box on the form removed and use a label (or button) that has a macro which closes "frmReports" and also does other things such as in yor case open Switchboard. Sometimes I leave the control box and X and my Close Label might have a little instruction as to when to use it.

    If you want to use two labels or two buttons then have one of the button or labels property set to visible and the other invisible. You can overlay them so they have exactly the same position on the form and are exactly the same size.

    When the form opens one of the buttons or labels will be visible. You attack a macro or code OnClick to perform what you want done but in addition it makes the other label or buttom visible and makes itself invisible. The reverse is done of the other label or button.

    I mch prefer macros for this sort of thing because often there are quite a few combinations of visible/invisible and it easy to fould yourself up. With Macros as opposed to code in the form you just show the data base window and change the macro and the click anywhere on the form so the form becomes the active object and run the macro again see how it goes. The if you prefer the idea of code in a form control Access will convert the macro to code for you.

    Mike

  4. #4
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183
    I have use openArgs to open "frmReports" but now i don't know what to do when i close the form ? Do i need to write if then statment when i close the "frmReports" ? I haven't used openArg before. Do you have any example that i can see ?
    Skharva

  5. #5
    Join Date
    Oct 2003
    Posts
    66
    Quote Originally Posted by Skharva
    I have use openArgs to open "frmReports" but now i don't know what to do when i close the form ? Do i need to write if then statment when i close the "frmReports" ? I haven't used openArg before. Do you have any example that i can see ?
    On frmMain use this in the click event for the command button that calls the frmReports form:
    DoCmd.OpenForm "frmReports", , , , , , "CallingForm:frmMain"

    Do this for the button that calls frmReport from the switchboard
    DoCmd.OpenForm "frmReports", , , , , , "CallingForm:switchboard"

    Do this in the click event for the button that close frmReport:
    If Me.OpenArgs = "CallingForm:frmMain" Then
    docmd.openform "frmMain"
    elseif Me.OpenArgs = "CallingForm:switchboard" then
    docmd.openform "switchboard"
    End If

    Please Note the names of you forms may be different from example but this shoudl get you on your way...Hope this helps good luck.

  6. #6
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Thumbs up

    Thanks i'm sure i can use this in my application
    Skharva

  7. #7
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183
    How can i use openArg...with option and reports ?

    I have 2 option button for the reports. When user clicks on any of these option button combo box get display form them to filter out the reports. Both of the option button uses same combo box for filteration. I also have "txtStart" and "txtEnd" date range on my form so user can filter out the reports by combo and then by date range.

    I have used after update of combo box to make "txtStartDate" and "txtEndDate" visible. I want this to be true only when Option1 is click when option2 is click i want user to only choose value from combo box.

    So how can i not make txtStartdate and txtEnddate visible when the 2nd option is click ?

    Thanks
    Skharva

  8. #8
    Join Date
    Sep 2003
    Location
    Raleigh, NC
    Posts
    183

    Thumbs up

    Got it......I use If...Then
    Skharva

Posting Permissions

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