Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing data to a new form on open

Status
Not open for further replies.

tpowers

Technical User
Nov 2, 2002
153
US
I have a field that the user will enter information into. Once they have entered the needed data there is a button that will open a second form on top of the first form. This form needs to auto fill with data from the first form. How can I pass the data in one field on the first form to a second field on the second form?

I am using Access 2000.

Thank you in advance

 
Can the me. option be used with a var

IE: me.varusername = forms!firstform.textbox


Thanks for all your help.

 
what is me.varusername is it a control then yes if the value in forms!firstform.textbox is valid for me.varusername
if it is a module level var then use varusername=forms!firstform.textbox
ther is a 2nd way of passing the info with the openargs
docmd.openform "formname",,,,me.textbox
then in the 2nd form use me.textbox=me.openargs


 
So me.textbox whould be the textbox that has the value I want to pass to the second form and me.openargs will pull in the value. Please don't mind me but I am still new at this stuff, so I don't understatnd the logic behind this code can explain how the data goes from one form to the next form.

Thank you for your help so far. and thank you for any help that you may provide me.

 
I am trying to accomplish a similar goal, however, I am trying to transfer data from several txtBoxes to txtBoxes on the new form. How would one accomplish that using the above OpenArgs method?
 
Well, here is what I am tring to do.

I have a form that allows the user to type in a name in the database once the type in this name and click on find name a second form pops up and displays any and all matchs in the data base for the name they typed in. next they can dbl click on the name that they are looking for and the database will return a the records that are linked to that name in a datasheet based on a query. this is where I start to lose it. if there are no records in the database for a certain name then the user needs the option to enter a new record. this is done by clicking on a button that is entitled Add/New. the code that I am having such a hard time with, is making the database take all the information from the name screen and place it into the correct field on on the record screen. does any of this make since to anyone.

If so, Please help me.



Thank you,

TPowers
 
It seems we have a similar goal. Here is what I did. I have a combo box that looks up file numbers, then when the user finds the file number with the matching data he wants...ie...AttyFileNo, Attention, Attorney,...(these are things that would go with the file number that he can then transfer to a new Order). I have a command button that says new order using this data (Something Like that) and has the following OnClick procedure to open my other form:

Private Sub cmdNewOrderFileNo_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmNewOrder"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd, acDialog, "Start" 'Start is my OpenArgs'
End Sub


Then my frmNewOrder forms OnLoad Event has the following code:

Private Sub Form_Load()
If Me.OpenArgs = "Start" Then
Me.txtAttention = Forms!frmStartOrder.Attention
Me.txtAttorney = Forms!frmStartOrder.Attorney
Me.txtAttyFileNo = Forms!frmStartOrder.AttyFileNo
End If
End Sub

Then I have another command button with the same OnClick code except I didn't put "Start" as an open arg.

It works great for me, and if I am understanding you correctly, then tinkering with that a little might be helpful. Hope it makes sense. I am not a programmer and have to find my own little ways around things sometimes.
 
Well I do think that this will help, however I would like to know how to just pass data from one form to the next. I tried the very first option that was provided in this theard but I get a debug error that states that this method is not supported. Is there something that I have to ref. for this to be supported or am I doing something wrong with the code?

Here is the code that I entered.


Private Sub Form_Load()
Me.txtVarFName = Forms!ContactInquiry!ContactSearch.txtContactFName
Me.txtVarAgency = Forms!ContactInquiry!ContactSearch.txtAgency
Me.txtVarPhone = Forms!ContactInquiry!ContactSearch.txtContactPhone
Me.txtVarExt = Forms!ContactInquiry!ContactSearch.txtExtension
End Sub

See this code is tring to pull data from the form that is still open but hidden behind this new form. Now on the other form there is no code concerning this.
 
I apologize for not understanding even with all this detail. What I want to do is similar. I have set a variable (global) in form #1 and want to display the value of that variable in form #2. Thus I need to pass the contents of a variable from form #1 to form #2. In fact I will want this displayed on all the forms once I get past form #1. It seems that the text above is focused on passing information in a textbox. The variable issue was mentioned, but I didn't quite figure out the response. Thanks in advance for any suggestions.
 
In response to setting a 'global' variable in a form, thats not quite the way there. Try setting the the variable in a module first in the general declarations section (at the top) of the module e.g.

Public myVariable as Variant

If you use a button or whatever to call a procedure, then put something like

myVariable=VALUE


In the form that you are opening, go to the On Load event, create an event procedure and enter the code

[myTextBox]=myVariable

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top