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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting(highlight) from a listbox!

Status
Not open for further replies.

shy216

Programmer
Jul 21, 2005
142
US
if i have a listbox. is there a way user can select from that listbox and click a command button which will update other field from another form?
ie. lstTransFrom (if user highlights from the list)
from frmTF
cmdUpdate (then user clicks this command button)
Balance (from table.([Bud].[Balance]) (update this field from the table?)
 
Code:
Private Sub Command2_Click()
    Me.txtBox.Value = DLookup("[FieldName]", "[TableName]", "[TableName].[FieldName] = '" & Me.List0.Value & "'")
End Sub

You don't even need the command button. You could just use the List box's Click event.

-------------------------
Just call me Captain Awesome.
 
How are ya shy216 . . .

Although a few more particulars would help, try this in the [blue]AfterUpdate[/blue] event of the listbox ([blue]you![/blue] substitute proper names/values in [purple]purple[/purple]):
Code:
[blue]   Dim srcFrm As Form, desFrm As Form, LBx As ListBox
   Dim Criteria As String, DLK
   
   If CurrentProject.AllForms([purple][b]DestinationFormName[/b][/purple]).IsLoaded Then
      Set srcFrm = Forms!frmTF
      Set desFrm = Forms([purple][b]DestinationFormName[/b][/purple])
      Set LBx = srcFrm![[purple][b]ListBoxName[/b][/purple]]
      
      Criteria = "[[purple][b]FieldName[/b][/purple]] = [red][b]'[/b][/red]" & LBx.Column(1) & "[red][b]'[/b][/red]"
      DLK = DLookup("[Balance]", "[purple][b]TableName[/b][/purple]", Criteria)
      
      If IsNull(DLK) Then
         MsgBox "Record Not Found!"
      Else
         desFrm!Balance = DLK
      End If
      
      Set LBx = Nothing
      Set desFrm = Nothing
      Set srcFrm = Nothing
   End If[/blue]
[ol][li] If the column your using in the listbox is [red]numeric[/red], remove the single [red]red[/red] quotes.[/li]
[li]You may have to play with the column(?) to get the right column.[/li]
[li]The command button is not required in this method. Activation occurs when user selects from the listbox.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
i get the basic concept now. thank you. one problem tho.
i have added another field on that same form (txtamount).
this is what's happening. from the main form. user clicks to open frmTransferFrom. on this form, they type in the amount and select from the lstBud where the money is taken out from. then when they click cmdSelect, it'll open up a frmTransferTo. amount and everything is set so that it shows the same amount. but user needs to make a different selection from the lstBud on frmTransferTo.
so i need to find a way that when i do click update from frmTransferTo, it'll subtract given amount from selection from [frmTransferFrom].[lstbud] and add to [frmTransferTo].[lstbud]. am i making sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top