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

Display Record Selected In List Box

Status
Not open for further replies.

rabbithole

Programmer
May 5, 2000
8
AU
rabbithole (Programmer) May 5, 2000 <br>I am trying to conduct a search on an access database table - the records found are then display in a list box.<br>Once a specific record is chosen from the listbox - I am seeking to display same record on a view form.<br><br>Code so far being =<br><br>Sub Search<br><br>&nbsp;&nbsp;&nbsp;&nbsp;letter = txtSearchFind.Text<br>&nbsp;&nbsp;&nbsp;&nbsp;st = &quot;FirstName like '&quot; & letter & &quot;*' &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;Data1.Refresh<br>&nbsp;&nbsp;&nbsp;&nbsp;Do While True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Data1.Recordset.FindNext st<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lstSearchMatches.AddItem_&nbsp;&nbsp;Data1.Recordset.Fields &quot;FirstName&quot;).Value&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Data1.Recordset.NoMatch = True Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Do<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br>End Sub<br><br>Sub View_Record<br><br>If frmSearch.lstSearchMatches.Selected(lstSearchMatches.ListIndex) = True Then<br>frmView.Show (lstSearchMatches.List(lstSearchMatches.ListIndex))<br>End Sub<br><br>PROMPT HELP WOULD BE GREATLY APPRECIATED!!!!!!&nbsp;&nbsp;<br>
 
RabbitHole-<br><br>In the call to load your view form, you're passing the field value that was stored in the list in the call to the .Show method.&nbsp;&nbsp;You can't do this, as the .Show method typically expects a VB constant (typically 'vbModal', or nothing at all).<br><br>To pass variables between forms is one of the fundamental challenges of Visual Basic. You can use one of several methods:<br><br>a) Global Variables<br>b) A custom public method that takes parameters<br>c) Public properties<br><br>Global Variables will eventually get you in trouble, so don't use them unless you really <i>really</i> have to.<br><br>The public method is not too bad, unless you want to pass more than about 8 or 10 variables, then it gets awkward.<br><br>I would recommend you set up a set of public properties in the view form to accept values passed in.&nbsp;&nbsp;You then code a public sub to show the form.&nbsp;&nbsp;So you'd code something like:<br><FONT FACE=monospace><br><i><b>ListForm</b></i><br>&nbsp;&nbsp;&nbsp;&nbsp;Load frmView<br>&nbsp;&nbsp;&nbsp;&nbsp;frmView.FirstName = lstSearchMatches.List(lstSearchMatches.ListIndex)<br>&nbsp;&nbsp;&nbsp;&nbsp;frmView.ShowIt vbModal<br><br><i><b>ViewForm</b></i><br>private m_Name as string<br><br>Public Property Let FirstName(RHS as String)<br>&nbsp;&nbsp;&nbsp;&nbsp;m_Name = RHS<br>End Property<br><br>Public Sub ShowIt(Modality as long)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;' Load rest of record based off of key value m_Name<br>&nbsp;&nbsp;&nbsp;&nbsp;txtFName.Text = m_Name<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Me.Show Modality<br>End Sub<br></font><br><br>Chip H.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top