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!

Populate text field from ListBox on another Form 1

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
Below is the code that allows me to add multiple names from a listbox to a field on a form.
I have changed the ListBox to a separate form. I am stumped as to how to select the names
from the listbox form and have them appear in a textbox on another form.

The Form name where the ListBox is located is "NamesMeFrm" the ListBox name is "MfgEngList"

The Form Name where the Textbox is located is "ECNDetailFrm" and the
Textbox name is "Engineering_Distribution".

I want to select the names from the listbox on one form and have them appear in the text box on the other
form.

Code:
  Dim varItem As Variant
  Dim strEngineer As String
  For Each varItem In Me.MfgEngList.ItemsSelected
    strEngineer = strEngineer & Me.MfgEngList.ItemData(varItem) & vbCrLf
  Next varItem
    strEngineer = Trim(strEngineer)
    Me.Engineering_Distribution = strEngineer

Thanks for any help!
 
Change
Code:
Me.Engineering_Distribution = strEngineer
[i]to[/i]
ECNDetailFrm.Engineering_Distribution = strEngineer
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks Harley,

The Engineering_Distribution Textbox is where I have code
in the OnClick Event that opens the Form NamesMeFrm that
has the ListBox with the names. In the AfterUpdate Event
of that Form I have put the code to populate the
Engineering_Distribution Textbox field on Form ECNDetailFrm.
Below is the code. The Engineering_Distribution Textbox
Field is not populating. Can you tell me what I am doing
wrong?

Code:
Private Sub Form_AfterUpdate()
 
  Dim varItem As Variant
  Dim strEngineer As String
  For Each varItem In Me.MfgEngList.ItemsSelected
    strEngineer = strEngineer & Me.MfgEngList.ItemData(varItem) & vbCrLf
  Next varItem
    strEngineer = Trim(strEngineer)
'    Me.Engineering_Distribution = strEngineer
    ECNDetailfrm.Engineering_Distribution = strEngineer
End Sub
 
Harley, please ignore my last post. I did not have the
code in the Listbox AfterUpdate event.

However, after putting the code in the Listbox AfterUpdate
Event the code is blowing up on

Code:
    ECNDetailfrm.Engineering_Distribution = strEngineer

Can you tell me what is wrong?
 
It is showing Runtime error 424

Object Required
 
Sorry, my mistake. Try:
Code:
Forms!ECNDetailfrm!Engineering_Distribution = strEngineer
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Harley,

I am getting a run-time error 2450"
Berea ECN/BCN/VIP Database can't find the form "ECNDetailfrm'
referred to in a macro expression or Visual Basic code.

The ECNDetailfrm is a subform of another form. I don't know
if this has anything to do with it or not. When I open
the Subform by itself the code works just fine. Any advice?
 
Yeah, that would make a difference if the subform's opened with it's parent form. Try syntax like this:
Code:
Forms!YourSubformsParentForm!ECNDetailfrm!Engineering_Distribution = strEngineer
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Harley,

I figured it out by showing both forms. Thanks for your help
with this.


Code:
  Forms!ECNBCNVIPfrm!ECNDetailfrm![Engineering Distribution] = strEngineer
 
Glad I could help, thanks for the star [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top