If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Can a form see which button opened it?
Hi, I want to use the same form to Add new data and to display results from a
query. The two buttons themselves are on different forms. The query displays all the inventory for a client code and the add new just tacks a new record on at the end (acNewRecord). Is there an OnOpen function that can check to see if the button was the Add_New button and go to acNewRecord and if not then to execute the query? |
#2
|
|||
|
|||
May be that the easier approach is to use the OpenArgs argument of the
OpenForm action to tell the form which button called it: DoCmd.OpenForm "FormName", OpenArgs:="ButtonName" Then you can use the Load event to run code that reads the OpenArgs in the second form and to set the value of an invisible textbox on that form based on that value: Private Sub Form_Load() If Me.OpenArgs = "AddNewButton" Then Me.txtBox.Value = "new" Else Me.txtBox.Value = "old" End Then use the value of this textbox to know what the second form should do. -- Ken Snell MS ACCESS MVP "Nick in Tokyo" wrote in message ... Hi, I want to use the same form to Add new data and to display results from a query. The two buttons themselves are on different forms. The query displays all the inventory for a client code and the add new just tacks a new record on at the end (acNewRecord). Is there an OnOpen function that can check to see if the button was the Add_New button and go to acNewRecord and if not then to execute the query? |
#3
|
|||
|
|||
I can see what you mean but can't quite use it right.
My Form is based on a select query, which gets it's condition from a combo box. ie, you select a client and then open the form which displays all the hardware information for that client. Can I execute the query from within the form? ... If Me.OpenArgs = "AddNew" DoCmd.GoToRecord , , acNewRec Else Execute a select query and disply results in form. "Ken Snell [MVP]" wrote: May be that the easier approach is to use the OpenArgs argument of the OpenForm action to tell the form which button called it: DoCmd.OpenForm "FormName", OpenArgs:="ButtonName" Then you can use the Load event to run code that reads the OpenArgs in the second form and to set the value of an invisible textbox on that form based on that value: Private Sub Form_Load() If Me.OpenArgs = "AddNewButton" Then Me.txtBox.Value = "new" Else Me.txtBox.Value = "old" End Then use the value of this textbox to know what the second form should do. -- Ken Snell MS ACCESS MVP "Nick in Tokyo" wrote in message ... Hi, I want to use the same form to Add new data and to display results from a query. The two buttons themselves are on different forms. The query displays all the inventory for a client code and the add new just tacks a new record on at the end (acNewRecord). Is there an OnOpen function that can check to see if the button was the Add_New button and go to acNewRecord and if not then to execute the query? |
#4
|
|||
|
|||
I'd do something like this:
Private Sub Form_Load() If Me.OpenArgs = "AddNew" Then Me.DataEntry = True Else Me.DataEntry = False End If No need to "run" the query if that query is the Record Source for the form that you're opening. Just use the above code. -- Ken Snell MS ACCESS MVP "Nick in Tokyo" wrote in message ... I can see what you mean but can't quite use it right. My Form is based on a select query, which gets it's condition from a combo box. ie, you select a client and then open the form which displays all the hardware information for that client. Can I execute the query from within the form? ... If Me.OpenArgs = "AddNew" DoCmd.GoToRecord , , acNewRec Else Execute a select query and disply results in form. "Ken Snell [MVP]" wrote: May be that the easier approach is to use the OpenArgs argument of the OpenForm action to tell the form which button called it: DoCmd.OpenForm "FormName", OpenArgs:="ButtonName" Then you can use the Load event to run code that reads the OpenArgs in the second form and to set the value of an invisible textbox on that form based on that value: Private Sub Form_Load() If Me.OpenArgs = "AddNewButton" Then Me.txtBox.Value = "new" Else Me.txtBox.Value = "old" End Then use the value of this textbox to know what the second form should do. -- Ken Snell MS ACCESS MVP "Nick in Tokyo" wrote in message ... Hi, I want to use the same form to Add new data and to display results from a query. The two buttons themselves are on different forms. The query displays all the inventory for a client code and the add new just tacks a new record on at the end (acNewRecord). Is there an OnOpen function that can check to see if the button was the Add_New button and go to acNewRecord and if not then to execute the query? |
#5
|
|||
|
|||
Great. Works fine.
Thanks I'd do something like this: Private Sub Form_Load() If Me.OpenArgs = "AddNew" Then Me.DataEntry = True Else Me.DataEntry = False End If No need to "run" the query if that query is the Record Source for the form that you're opening. Just use the above code. -- Ken Snell MS ACCESS MVP "Nick in Tokyo" wrote in message ... I can see what you mean but can't quite use it right. My Form is based on a select query, which gets it's condition from a combo box. ie, you select a client and then open the form which displays all the hardware information for that client. Can I execute the query from within the form? ... If Me.OpenArgs = "AddNew" DoCmd.GoToRecord , , acNewRec Else Execute a select query and disply results in form. "Ken Snell [MVP]" wrote: May be that the easier approach is to use the OpenArgs argument of the OpenForm action to tell the form which button called it: DoCmd.OpenForm "FormName", OpenArgs:="ButtonName" Then you can use the Load event to run code that reads the OpenArgs in the second form and to set the value of an invisible textbox on that form based on that value: Private Sub Form_Load() If Me.OpenArgs = "AddNewButton" Then Me.txtBox.Value = "new" Else Me.txtBox.Value = "old" End Then use the value of this textbox to know what the second form should do. -- Ken Snell MS ACCESS MVP "Nick in Tokyo" wrote in message ... Hi, I want to use the same form to Add new data and to display results from a query. The two buttons themselves are on different forms. The query displays all the inventory for a client code and the add new just tacks a new record on at the end (acNewRecord). Is there an OnOpen function that can check to see if the button was the Add_New button and go to acNewRecord and if not then to execute the query? |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Strange stLinkCriteria behaviour on command button | Anthony Dowd | Using Forms | 3 | August 21st, 2004 03:01 AM |
Default values to load up automatically in a form based on value entered in another form | Anthony Dowd | Using Forms | 8 | August 12th, 2004 08:53 AM |
synchronizing form and list box | Deb Smith | Using Forms | 8 | June 21st, 2004 08:15 PM |
Problem Opening Another Form with a Button | Chip | Using Forms | 1 | June 6th, 2004 08:18 AM |
Protect Form Button | McDaniel | General Discussion | 2 | May 21st, 2004 08:37 PM |