Brain teaser -- "Passing data from an unbound text in one form to another textbox in another form"

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

I am wondering if someone has a good idea for an approach of "transferring
data" from form to form.

Here's what I have:
- Main form with 10 texboxes (with visible property).

Here's what I'd like to achieve:
- Add another 10 textboxes (with invisible property)
- Place 10 command buttons ("Enter comment") next to the 10 visible
textboxes
- When either one of the 10 command buttons ("Enter command") is clicked,
another form pops up.
- That pop-up form has a single unbound textbox.
- Once form is closed, the value entered into the unbound textbox of the
pop-up form is passed into the invisible textbox of the mainform (next to
the command button)

In other words, here's the process step-by-step:
===============================
1. Mainform has e.g. a value of "2" in the VISIBLE_TEXTBOX_5A
2. User must provide comment as to why "2" was chosen as the answer. The
explanation must be stored in IN_VISIBLE_TEXTBOX_5B. However, since
IN_VISIBLE_TEXTBOX_5B is invisible (duh), user certainly can't do it...
instead,
3. User will click on COMMAND_BUTTON_5
4. COMMAND_BUTTON_5 opens up another form
5. User provides explanation in UNBOUND_TEXTBOX as to why "2" was chosen in
VISIBLE_TEXTBOX_5A
6. User closes pop-up form
7. Closing the pop-up form will transfer text string from UNBOUND_TEXTBOX
into IN_VISIBLE_TEXTBOX_5B

Does anyone have an ideas as to how I can make the "transfer" from unbound
textbox to another textbox
(from one form to another)? The only link between these is the controlname
of the command button (commandbutton5).


Thanks,
Tom
 
Tom wrote:
[snip]
Here's what I'd like to achieve:
- Add another 10 textboxes (with invisible property)
- Place 10 command buttons ("Enter comment") next to the 10 visible
textboxes
- When either one of the 10 command buttons ("Enter command") is
clicked, another form pops up.
- That pop-up form has a single unbound textbox.
- Once form is closed, the value entered into the unbound textbox of
the pop-up form is passed into the invisible textbox of the mainform
(next to the command button)
[snip]

You open the form with the acDialog option. This causes your calling code to
pause until the opened form is either closed or hidden (that last is the key).
Make your called form have an [OK] and a [Cancel] button. The Cancel button
closes the form and the OK button only hides it. Then your calling code looks
like...

DoCmd.OpenForm "PopUpFormName",,,,, acDialog
If IsLoaded("PopUpFormName") = True
'User pressed OK
Me.TextBoxName = Forms!PopUpFormName!TextBoxName
DoCmd.Close acForm, "PopUpFormName"
Else
'User pressed Cancel
End If

You will need a copy of the custom function IsLoaded() from the sample
Northwinds database or you can use a similar built in method in the newer
versions.
 
Rick:

Thanks, I'll give a try... I may post some follow-up questions tomorrow.
Hopefully you keep watching this thread for a day or two.
--
Thanks again,
Tom


Rick Brandt said:
Tom wrote:
[snip]
Here's what I'd like to achieve:
- Add another 10 textboxes (with invisible property)
- Place 10 command buttons ("Enter comment") next to the 10 visible
textboxes
- When either one of the 10 command buttons ("Enter command") is
clicked, another form pops up.
- That pop-up form has a single unbound textbox.
- Once form is closed, the value entered into the unbound textbox of
the pop-up form is passed into the invisible textbox of the mainform
(next to the command button)
[snip]

You open the form with the acDialog option. This causes your calling code
to pause until the opened form is either closed or hidden (that last is
the key). Make your called form have an [OK] and a [Cancel] button. The
Cancel button closes the form and the OK button only hides it. Then your
calling code looks like...

DoCmd.OpenForm "PopUpFormName",,,,, acDialog
If IsLoaded("PopUpFormName") = True
'User pressed OK
Me.TextBoxName = Forms!PopUpFormName!TextBoxName
DoCmd.Close acForm, "PopUpFormName"
Else
'User pressed Cancel
End If

You will need a copy of the custom function IsLoaded() from the sample
Northwinds database or you can use a similar built in method in the newer
versions.
 
Rick:

Again, thanks for the feedback. I checked the Northwind db and found many
instances of the "IsLoaded".

I'm not too familiar w/ the concept, so I don't know as to which function I
need to copy into my apps.

Do you happen to know of a small sample db to which you could point me to.
If possible, the single popup has at least 1 textbox and 1 combo box which
would allow me to pass those values from popup to mainform.

Last thing... once something was entered in the popup and the value was sent
to the mainform, I need to bring up the same value again if someone clicks
the proper command button. Essentially, individuals must be able to edit
information once entered.

Any ideas?

Thanks,
Tom



Rick Brandt said:
Tom wrote:
[snip]
Here's what I'd like to achieve:
- Add another 10 textboxes (with invisible property)
- Place 10 command buttons ("Enter comment") next to the 10 visible
textboxes
- When either one of the 10 command buttons ("Enter command") is
clicked, another form pops up.
- That pop-up form has a single unbound textbox.
- Once form is closed, the value entered into the unbound textbox of
the pop-up form is passed into the invisible textbox of the mainform
(next to the command button)
[snip]

You open the form with the acDialog option. This causes your calling code to
pause until the opened form is either closed or hidden (that last is the key).
Make your called form have an [OK] and a [Cancel] button. The Cancel button
closes the form and the OK button only hides it. Then your calling code looks
like...

DoCmd.OpenForm "PopUpFormName",,,,, acDialog
If IsLoaded("PopUpFormName") = True
'User pressed OK
Me.TextBoxName = Forms!PopUpFormName!TextBoxName
DoCmd.Close acForm, "PopUpFormName"
Else
'User pressed Cancel
End If

You will need a copy of the custom function IsLoaded() from the sample
Northwinds database or you can use a similar built in method in the newer
versions.
 
Tom said:
Rick:

Again, thanks for the feedback. I checked the Northwind db and
found many instances of the "IsLoaded".

I'm not too familiar w/ the concept, so I don't know as to which
function I need to copy into my apps.

Place the following in a normal module. Afterwards you will be able to use
the function just as you would a built in one.

Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Do you happen to know of a small sample db to which you could point
me to. If possible, the single popup has at least 1 textbox and 1
combo box which would allow me to pass those values from popup to
mainform.

With my example code the popup form is still open (though hidden) when the
user makes entries and then presses OK. Your calling code is free to pull
as many or as few of those values from the popup form before closing it as
you need.
Last thing... once something was entered in the popup and the value
was sent to the mainform, I need to bring up the same value again if
someone clicks the proper command button. Essentially, individuals
must be able to edit information once entered.

The popup form's open event could "look back" at the field on the calling
form and if it already has a value then it can copy that value into the
popup's controls.
 
Albert:

Thanks for the feedback... you're making a good point about the
differences... still trying to really understand what they're. Maybe w/
your help, I'll get closer to the answer.

I was wondering if you have a small sample db that does exactly what
describe.

- click on e.g. command button on main form
- enter data in textbox and make selection from combo
- click OK on "popup" form
- transfer entered/selected data from popup from mainform

Or maybe you could point me to a great sample file somewhere on the
internet.
 
I was wondering if you have a small sample db that does exactly what
describe.

- click on e.g. command button on main form
- enter data in textbox and make selection from combo
- click OK on "popup" form
- transfer entered/selected data from popup from mainform

The sample code in that article does exactly the above. since the code is
written, you should at least have the skills to design a form with a few
text boxes on it? Surely, you can built a form with a few text boxes on it?
If there is any part of this code that is un-clear...please ask. That web
article has step by step instructions here.

The sample code posted is:
dim strF as string

' lets open a prompt form
strF = "frmGetComboName"
docmd.OpenForm strF,acNormal,,,,acDialog

if isloaded(strF) = true then
' code goes here to grab example values
strName = forms(strF)!ThenameField
strSex = fomrs(strF)!GenderField
' ok, got our data...lets close the form (don't forget this!!)
docmd.Close acForm,strF
else
' if the form is not open, then user hit the "x", or the cancel
' button on the frmGetComboName form. Note that the cancel button on
' this form simply does a docmd.close
msgbox "user canceled"
end if

In the above code, any of those field names (like the GenderField) could be
a combo box. The only thing left on your part is to paste the above code,
and make your "prompt" form with the un-bound controls on it.
 
Back
Top