Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2006, 05:39 PM
Authorized User
 
Join Date: Dec 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to put a value into another form's text box?

I have a form (form2) with a listbox of names. What I want is that when users wanting to edit a name in the list can double-click it to open a second form (form3) in which the name is shown in a text box; when they have finished editing they close the second form and the new version of the name is passed back to a text-box on the first form.

The bit I can't get to work is ensuring that the text-box on the second form contains the selected value when it's opened. When the second form opens, the text-box is always empty ! I've tried:

-setting it by code in the first form:
[Forms]![form3].[txtItem].Value = Me.List0.Value

-setting it by code in the second form:
Me.txtItem.Value = [Forms]![form2].List0.Value

-setting the default value of the second form's text-box:
=[Forms]![Form2]![List0]
 
Old December 17th, 2006, 09:03 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the property you need is the source of the textbox. It should be the second box on the properties screen. put [Forms]![Nameofyourform]![Nameoftextbox].

HTH

Dave

 
Old December 18th, 2006, 08:23 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You could pass it to a public variable if the form references are not working.

On the double click event of the list box, put this:

Public sValue As String

sValue = Me.List0

I wouldn't use "Me.List0.Value"

Then on the On Open event of the next form, do this:

Me.txtItem = sValue

I think what may also be the problem is that when you use .Value on the second text box, that it sets the value, but doesn't display the value. Leave .Value off and see what happens too.

Did that help?


mmcdonal
 
Old December 20th, 2006, 06:19 PM
Authorized User
 
Join Date: Dec 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your suggestion, the public variable worked with a little extra trial and error. The only combination I've found that works has all the code in the first form (form2, which opens form3 when the list box is double clicked). The code in form2 is:

Public strSelectedItem As String



Private Sub List0_DblClick(Cancel As Integer)

Dim varItem As Variant

'================================================= ====
' set strSelectedItem to the selected item in the
' list box. This approach is necessary because
' multiple selections are enabled for the list box
' (necessary for other purposes).
'================================================= ====

With Me.List0
    For Each varItem In .ItemsSelected
    strSelectedItem = .ItemData(varItem)
    Next
End With

DoCmd.OpenForm "form3"

'================================================= ====
' Set the textbox on the new form to the item to be edited
'================================================= ====

[Forms]![form3].[txtItem] = strSelectedItem

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
put mailto: links on list items in a combo box? webwolf Flash (all versions) 0 September 12th, 2008 08:01 AM
Put cursor at the end of input text peace2007 Javascript 1 October 11th, 2007 04:49 AM
Form's combo text box selection drives pull of a s pkaptein1 Access 3 May 5th, 2005 06:24 AM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.