Passing data from one form to another

O

oxicottin

Hello I have a form called frmMaindB and it has 5 text boxes on it
(txtEmployeeTime, txtDTRegular, txtDTReason1, txtDTReason2, txtDTMaintenance)

when I double click on the text box it opens up a pop up form named
frm_DecimalConversion. On this form I have two text boxes one box I enter
data into and the other calculates or converts the data to a decimal. The box

that converts the data is called txtDecimal. Then I have a close button which
I want to use to close the pop up form and insert the data into the text box
I double clicked in to get the pop up or (frm_DecimalConversion). I have read
that I need to use
the OpenArgs. But I have no clue how to get started? Someone told me to use
this in the text box I double click into to get the pop up form (Docmd.
OpenForm
"frm_DecimalConversion" , , , , , , 1) and to use a diferent numbers like
2,3,4,5 for the other text boxes I im using. Then they
told me to do this:

Then wherever you're running your code in your popup to populate the main
form textbox, use

Select Case Me.OpenArgs

Case 1 'this will be the textbox that you used the number 1
Forms!frmMaindB!TextBox1 = Me.txtDecimal

Case 2 'this will be the textbox that you used the number 2
Forms!frmMaindB!TextBox2 = Me.txtDecimal


Can someone please explain or give me an example of what I need to do
because I dont quite understand....In other word im lost...Thanks!
 
C

Carl Rapson

oxicottin said:
Hello I have a form called frmMaindB and it has 5 text boxes on it
(txtEmployeeTime, txtDTRegular, txtDTReason1, txtDTReason2,
txtDTMaintenance)

when I double click on the text box it opens up a pop up form named
frm_DecimalConversion. On this form I have two text boxes one box I enter
data into and the other calculates or converts the data to a decimal. The
box

that converts the data is called txtDecimal. Then I have a close button
which
I want to use to close the pop up form and insert the data into the text
box
I double clicked in to get the pop up or (frm_DecimalConversion). I have
read
that I need to use
the OpenArgs. But I have no clue how to get started? Someone told me to
use
this in the text box I double click into to get the pop up form (Docmd.
OpenForm
"frm_DecimalConversion" , , , , , , 1) and to use a diferent numbers like
2,3,4,5 for the other text boxes I im using. Then they
told me to do this:

Then wherever you're running your code in your popup to populate the main
form textbox, use

Select Case Me.OpenArgs

Case 1 'this will be the textbox that you used the number 1
Forms!frmMaindB!TextBox1 = Me.txtDecimal

Case 2 'this will be the textbox that you used the number 2
Forms!frmMaindB!TextBox2 = Me.txtDecimal


Can someone please explain or give me an example of what I need to do
because I dont quite understand....In other word im lost...Thanks!

If it were me, I'd probably use a global variable instead. Add a module to
your application and in that module add a line like the following:

Public gDecimalValue

That's it, save and close the module. Now, in your popup form, when you're
ready to close and return the converted value to your main form (probably
the Click event of the close button), store the value in the global variable
before closing the form:

gDecimalValue = Me.txtDecimal

Now, back in your main form, on the line immediately following where you
opened the popup form, you can refer to the global value:

Me.TextBox1 = gDecimalValue

I assume this is all happening in the DoubleClick event of each textbox, so
you should already know which textbox was double-clicked (you'll be in its
DoubleClick event).

Carl Rapson
 
O

oxicottin

This was easy to understand and explained very well... I have some issues
though! The txtDecimal box has a number generated from the above text box
(txtMinutes) and in txtMinutes's After Update Event has this code to generate
the number needed:

Private Sub txtMinutes_AfterUpdate()
Me.txtDecimal = Round(Me.txtMinutes / 60, 2)
End Sub

Now in my close button on my form I have this code:

Private Sub cmdCloseDecimalConversion_Click()
gDecimalValue = Me.txtDecimal
DoCmd.Close
End Sub

The problem im haveing is that when I close the pop up form
(frm_DecimalConversion) the number isnt populated in the text box I double
clicked from just yet. I have to double click again on the box and the number
will populate but it opens up the pop up again. Is there a way around this?
or did I do something wrong? Also here is what I put in the double click
event for the text boxes on my frmMaindB. Thanks!!!

Private Sub txtDTMaintenance_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_DecimalConversion"
Me.txtDTMaintenance = gDecimalValue
End Sub

Private Sub txtDTReason1_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_DecimalConversion"
Me.txtDTReason1 = gDecimalValue
End Sub

Private Sub txtDTReason2_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_DecimalConversion"
Me.txtDTReason2 = gDecimalValue
End Sub

Private Sub txtDTRegular_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_DecimalConversion"
Me.txtDTRegular = gDecimalValue
End Sub

Private Sub txtEmployeeTime_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_DecimalConversion"
Me.txtEmployeeTime = gDecimalValue
End Sub
 
G

Guest

In the popup form where you do the calculation. In the click event of the
button you use to close the form, just populate the text box of the other
form with the value in the calculated text box.

Forms!TheOtherForm!TheOtherTextBox = Me.txtDecimal
 
O

oxicottin via AccessMonster.com

Im sorry I dont quite understand? Where would I add the formula you wrote? I
understand its in my close button of the pop up but I get an error when ran.
Is "TheOtherForm" my frmMaindB? and is the "TheOtherTextBox" the other text
box name on the pop ups form cales txtMinutes? If so can you give an example
of where it in inserted...Thanks a million!


Private Sub cmdCloseDecimalConversion_Click()

gDecimalValue = Me.txtDecimal
DoCmd.Close
 
G

Guest

If frmMaindB is the form you have open the opens your calculation form, the
answer is yes. The other text box is the text box on frmMaindB where you
want to display the results of the calculation.

Private Sub cmdCloseDecimalConversion_Click()

'Remove this line
' gDecimalValue = Me.txtDecimal
Forms!frmMaindB!txtSomeTextBox = Me.txtDecimal
DoCmd.Close
 
O

oxicottin via AccessMonster.com

Ok but this will only let me update one text box? the one where
"txtSomeTextBox" is. I wanted to be able to update the txt box I double
clicked into to get the pop up.

If frmMaindB is the form you have open the opens your calculation form, the
answer is yes. The other text box is the text box on frmMaindB where you
want to display the results of the calculation.

Private Sub cmdCloseDecimalConversion_Click()

'Remove this line
' gDecimalValue = Me.txtDecimal
Forms!frmMaindB!txtSomeTextBox = Me.txtDecimal
DoCmd.Close
Im sorry I dont quite understand? Where would I add the formula you wrote? I
understand its in my close button of the pop up but I get an error when ran.
[quoted text clipped - 6 lines]
gDecimalValue = Me.txtDecimal
DoCmd.Close
 
G

Guest

Okay, then use the name of that text box.
--
Dave Hargis, Microsoft Access MVP


oxicottin via AccessMonster.com said:
Ok but this will only let me update one text box? the one where
"txtSomeTextBox" is. I wanted to be able to update the txt box I double
clicked into to get the pop up.

If frmMaindB is the form you have open the opens your calculation form, the
answer is yes. The other text box is the text box on frmMaindB where you
want to display the results of the calculation.

Private Sub cmdCloseDecimalConversion_Click()

'Remove this line
' gDecimalValue = Me.txtDecimal
Forms!frmMaindB!txtSomeTextBox = Me.txtDecimal
DoCmd.Close
Im sorry I dont quite understand? Where would I add the formula you wrote? I
understand its in my close button of the pop up but I get an error when ran.
[quoted text clipped - 6 lines]
gDecimalValue = Me.txtDecimal
DoCmd.Close
 
C

Carl Rapson

Try this: in your OpenForm calls, add the acDialog parameter:

DoCmd.OpenForm "frm_DecimalConversion",,,,,acDialog

It may be that your parent form isn't pausing while the popup form runs, and
therefore there's no value to pick up. That would explain why you see the
value the second time around.

Carl Rapson
 
O

oxicottin via AccessMonster.com

That will do it!! Thanks..... Hay do you know any good access website with
tutorials and downloand databases? Thanks for the help it was musch
appreciated!

Carl said:
Try this: in your OpenForm calls, add the acDialog parameter:

DoCmd.OpenForm "frm_DecimalConversion",,,,,acDialog

It may be that your parent form isn't pausing while the popup form runs, and
therefore there's no value to pick up. That would explain why you see the
value the second time around.

Carl Rapson
This was easy to understand and explained very well... I have some issues
though! The txtDecimal box has a number generated from the above text box
[quoted text clipped - 46 lines]
Me.txtEmployeeTime = gDecimalValue
End Sub
 
C

Carl Rapson

Here are a few that I use frequently:

http://www.lebans.com/

http://www.mvps.org/access/

http://www.granite.ab.ca/accsmstr.htm

There are lots of others out there; you can use Google or some such to
search for them.

Carl Rapson

oxicottin via AccessMonster.com said:
That will do it!! Thanks..... Hay do you know any good access website with
tutorials and downloand databases? Thanks for the help it was musch
appreciated!

Carl said:
Try this: in your OpenForm calls, add the acDialog parameter:

DoCmd.OpenForm "frm_DecimalConversion",,,,,acDialog

It may be that your parent form isn't pausing while the popup form runs,
and
therefore there's no value to pick up. That would explain why you see the
value the second time around.

Carl Rapson
This was easy to understand and explained very well... I have some
issues
though! The txtDecimal box has a number generated from the above text
box
[quoted text clipped - 46 lines]
Me.txtEmployeeTime = gDecimalValue
End Sub
 

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