Transferring selection data from one form to another...

C

Chris Kersey

Hi,

I'm fairly new to programming in Access, and I'm having some trouble getting
a selected item (string and a long) from FORM B to FORM A.

setup

FORM A contains a bound text box that I placed a button next to labeled
"change". I created a macro behind this button that opens FORM B (which is
pretty much all it does). The reason for the second window is because there
is too much data to present in a drop down, so I created Form B to contain a
text box and a flex grid. As the user types letters into the textbox, the
db table is queried with "select * from foo where foo.bar='" & str & "*'
order by foo.bar". The result set I populate the flex grid and listen for a
doubleclick event from which to select the user's option.

problem

The purpose of the selection is to re-assign an existing association based
on the user's choice made on Form B. I can't seem to pass the required
information from FORM B back to FORM A where I can then update the db.

Things I've tried

1. I tried assiging the information directly back to FORMA.txtBox.value but
got an error "you can't do that unless the control has focus". I tried
setting focus, but even the focus throws an error I think because the form
on which it resides does not have focus.

2. I tried creating a public module contaning a public variable (go
between), but assigning to that, it seems to dissapear into the void.

QUESTION:
Is there a common way of doing this sort of thing in ACCESS? Is there a
parent/child setting?. In VB, I could do #2, or even raise an event to
trigger some global action, but the way ACCESS works is throwing me a curve
ball. Any help would be greatly appreciated.

Code on request.

Chris Kersey
 
K

kevin

Tru using just formA.textbox=your data. I believe if you
use the .value expression that the control does have to
have the focus.

Hope that helps!

Kevin
 
C

Chris Kersey

Thanks for your reply. I finally managed a work around. The OnClick event
for the button on FormA, I added a reference to some Public variables I
created on Form B that looked like this:

Private Sub cmdChangeBroker_Click()
DoCmd.OpenForm "BrokerageList", acNormal
Form_BrokerageList.txtBrokerageName = Form_BROKER.Brokerage
Form_BrokerageList.Broker_Key = [Broker_Key]
End Sub

then on the receiving form (Form B), I pull the reference to the key and
name fields to build an update query string. This seems to work fine. It
feels like a hack, and probably looks llike a hack, andbut unless there is a
more standard way of doing this sort of thing, I suppose it is a hack. :D

I didn't try the method below... it would surprise me if MS would actually
treat a default property differently than an explicit referece to one, but
then again, I'm sure there are all sorts of quirky behaviors to be found if
one digs deep enough :)

Thanks again!
Chris
 
A

Alick [MSFT]

Hi Chris,

As I understand you create an additional form FormB because the information
is too much to be filled in one form, if this is the case, I think you can
use tab control, this would be a better solution/design. For a sample about
using tab control, you can refer to the form Employees in the sample
database NorthWind.mdb (Help menu->sample databases)

Please feel free to reply to the threads if you have any concerns or
questions.


Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.






--------------------
| From: "Chris Kersey" <[email protected]>
| References: <[email protected]>
<018c01c38dbb$446b9d90
|
| Thanks for your reply. I finally managed a work around. The OnClick
event
| for the button on FormA, I added a reference to some Public variables I
| created on Form B that looked like this:
|
| Private Sub cmdChangeBroker_Click()
| DoCmd.OpenForm "BrokerageList", acNormal
| Form_BrokerageList.txtBrokerageName = Form_BROKER.Brokerage
| Form_BrokerageList.Broker_Key = [Broker_Key]
| End Sub
|
| then on the receiving form (Form B), I pull the reference to the key and
| name fields to build an update query string. This seems to work fine. It
| feels like a hack, and probably looks llike a hack, andbut unless there
is a
| more standard way of doing this sort of thing, I suppose it is a hack. :D
|
| I didn't try the method below... it would surprise me if MS would actually
| treat a default property differently than an explicit referece to one, but
| then again, I'm sure there are all sorts of quirky behaviors to be found
if
| one digs deep enough :)
|
| Thanks again!
| Chris
|
|
| | > Tru using just formA.textbox=your data. I believe if you
| > use the .value expression that the control does have to
| > have the focus.
| >
| > Hope that helps!
| >
| > Kevin
| > >-----Original Message-----
| > >Hi,
| > >
| > >I'm fairly new to programming in Access, and I'm having
| > some trouble getting
| > >a selected item (string and a long) from FORM B to FORM A.
| > >
| > >setup
| > >
| > >FORM A contains a bound text box that I placed a button
| > next to labeled
| > >"change". I created a macro behind this button that
| > opens FORM B (which is
| > >pretty much all it does). The reason for the second
| > window is because there
| > >is too much data to present in a drop down, so I created
| > Form B to contain a
| > >text box and a flex grid. As the user types letters into
| > the textbox, the
| > >db table is queried with "select * from foo where
| > foo.bar='" & str & "*'
| > >order by foo.bar". The result set I populate the flex
| > grid and listen for a
| > >doubleclick event from which to select the user's option.
| > >
| > >problem
| > >
| > >The purpose of the selection is to re-assign an existing
| > association based
| > >on the user's choice made on Form B. I can't seem to
| > pass the required
| > >information from FORM B back to FORM A where I can then
| > update the db.
| > >
| > >Things I've tried
| > >
| > >1. I tried assiging the information directly back to
| > FORMA.txtBox.value but
| > >got an error "you can't do that unless the control has
| > focus". I tried
| > >setting focus, but even the focus throws an error I think
| > because the form
| > >on which it resides does not have focus.
| > >
| > >2. I tried creating a public module contaning a public
| > variable (go
| > >between), but assigning to that, it seems to dissapear
| > into the void.
| > >
| > >QUESTION:
| > >Is there a common way of doing this sort of thing in
| > ACCESS? Is there a
| > >parent/child setting?. In VB, I could do #2, or even
| > raise an event to
| > >trigger some global action, but the way ACCESS works is
| > throwing me a curve
| > >ball. Any help would be greatly appreciated.
| > >
| > >Code on request.
| > >
| > >Chris Kersey
| > >
| > >
| > >.
| > >
|
|
|
 
M

Michel Walsh

Hi,


To access formA from formB, you may have tried:


FORMS!FormA!ControlOnFormA = something



where FORMS is a key word, but FormA and ControlOnFormA have to be changed
for the real things.

You generally do NOT need to have the focus to change the VALUE property.
You need if you try to change the TEXT property, since, in Access, the TEXT
property is what the user is actually typing, while the VALUE is a kind of
the last validated final input for that control (validation at the control
level, not necessary at the table level, for that one, rather use OLDVALUE
property).

Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top