A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can a form see which button opened it?



 
 
Thread Tools Display Modes
  #1  
Old August 25th, 2004, 01:59 AM
Nick in Tokyo
external usenet poster
 
Posts: n/a
Default 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  
Old August 25th, 2004, 02:07 AM
Ken Snell [MVP]
external usenet poster
 
Posts: n/a
Default

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  
Old August 25th, 2004, 02:55 AM
Nick in Tokyo
external usenet poster
 
Posts: n/a
Default

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  
Old August 25th, 2004, 04:19 AM
Ken Snell [MVP]
external usenet poster
 
Posts: n/a
Default

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  
Old August 25th, 2004, 05:37 AM
Nick in Tokyo
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 12:05 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.