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

Display a RecordSet for User Selection

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
THE SITUATION:&nbsp;&nbsp;I have a supplemental database which records and reports information on new admissions.&nbsp;&nbsp;Records are identified by a primary key “ClientID” and a secondary (indexed, duplicates allowed) “BillingID”.&nbsp;&nbsp;ClientID is an Autonumber field used as the main linking field between tables and is &quot;behind the scenes&quot; -- users would not know what a client's ClientID is.<br><br>The source documents, because of confidentiallity, are identified only by the BillingID and Completion Date (which usually is on or close to the Admission Date).&nbsp;&nbsp;I am retrieving the ClientID and other identifier information from the main database based on the BillingID.<br><br>Clients can have multiple admissions each of which generates a unique ClientID but the BillingID is reused.<br><br>THE PROBLEM:&nbsp;&nbsp;&nbsp;Because the BillingID is the field used in the SQL statement to retrieve the relevant information, I need a way for the user to associate the correct ClientID (based on the Admission Date being equal to or near the Completion Date of the source document) where a client has more than one admission.&nbsp;&nbsp;<br><br>What I would like to do, unless you have another approach, is to display a message indicating that multiple records exist on the BillingID and a list of Admission Dates and prompt the user to select the appropriate date.&nbsp;&nbsp;I could then set the pointer to the correct record to retrieve the information I need.<br><br>Here is my current code:<br><br>Private Sub txtOakLawnNum_AfterUpdate() ‘Oaklawn Number is the BillingID<br>On Error GoTo err_txtOaklawnNum_afterupdate<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim dbcurrent As Database<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim rsTemp As Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim strSQL As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim strOak As String<br><br>&nbsp;&nbsp;&nbsp;&nbsp;strOak = txtOaklawnNum<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Set dbcurrent = CurrentDb()<br>&nbsp;&nbsp;&nbsp;&nbsp;strSQL = &quot;SELECT ClientID, OaklawnNum, FullName, AdmissionDate &quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& &quot;FROM client &quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& &quot;WHERE OaklawnNum = '&quot; & strOak & &quot;';&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rsTemp = dbcurrent.OpenRecordset(strSQL)<br>&nbsp;&nbsp;&nbsp;&nbsp;rsTemp.MoveLast<br>&nbsp;&nbsp;&nbsp;&nbsp;rsTemp.MoveFirst<br><br>HERE IS WHERE I NEED SOME CODE:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;If rsTemp.RecordCount &gt; 1 then<br><br> Display some message to the user<br> Prompt the user for record Selection<br><br>&nbsp;&nbsp;&nbsp;End IF<br><br>THEN I WOULD SET THE RECORD POINTER BASED ON THE SELECTION<br><br>&nbsp;&nbsp;&nbsp;&nbsp;txtFullName = rsTemp.Fields(2)<br>&nbsp;&nbsp;&nbsp;&nbsp;txtAdmissionDate = rsTemp.Fields(3)<br>&nbsp;&nbsp;&nbsp;&nbsp;ClientID = rsTemp.Fields(0)<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;rsTemp.Close<br><br>Is there a way to display a recordset in this type of situation to allow the user to make a selection?<br><br>Is there a better way to accomplish what I am trying to do?<br><br>Thanks much.<br> <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
Larry,<br><br>I have a suggestion that might help.&nbsp;&nbsp;<br><br>On the same form, have a hidden list box.&nbsp;&nbsp;If you get multiple client id's, set the listbox to visible, build the list box with the results of the recorset admission dates.&nbsp;&nbsp;Display your message.&nbsp;&nbsp;When the user closes the message and double-clicks on an admission date, set the double-click event to trigger a new recordset that queries the table based on the admission date, and the billing id and Name already entered in the form.<br><br>What it boils down to is that you can build a list box (choose value list in the row source type) with the values of the recordset: <br><br>dim strDates as string<br><br>Do while not rsTemp.eof<br>&nbsp;&nbsp;&nbsp;&nbsp;if strDates &lt;&gt; &quot;&quot; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strDates = strDates & &quot;;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;endif<br>&nbsp;&nbsp;&nbsp;&nbsp;strDates = strDates & &quot;&quot;&quot;&quot; & rsTemp!AdmissionDate & &quot;&quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;if not rsTemp.eof then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rsTemp.movenext<br>&nbsp;&nbsp;&nbsp;&nbsp;end if<br>loop<br><br>me.lstDates.rowsource = strDates<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>Now, the rowsource for the list box contains the admission dates from the recordset.&nbsp;&nbsp;And when the user selects a date, you can kick off a new recordset using their selection.&nbsp;&nbsp;You could also do the same with a combo box to save vertical space.<br><br>I hope this helps.<br><br>-Chopper<br><A HREF="mailto:kenneth.mai@exch.compass-usa.com">kenneth.mai@exch.compass-usa.com</A><br>
 
Chopper:<br><br>The list box tip is a great idea.&nbsp;&nbsp;It works just fine except for one small problem.<br><br>The list box returns its value as a string and I don't know how to convert that to a date format for the new SQL string.<br><br>Everything I've tried so far has resulted a variable mismatch error.<br><br>Do I need to set up a property in the list box or is there a way to modify the returned string to a date format?<br><br>Thanks much.&nbsp;&nbsp; <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
Larry,<br><br>when you write the sql string and refer to the date selected, use the # character around the date, as in:<br><br>... WHERE Admission Date = #&quot; & me.lstDates.itemselected & &quot;#;&quot;<br><br>I believe this is the correct format for using a date in a sql string.&nbsp;&nbsp;You may wish to use the format statement inline to ensure you have the correct format, though I don't think you will need it.<br><br>I hope this helps,<br><br>Chopper
 
Yeah, I finally figured that out late yesterday.&nbsp;&nbsp;I was trying to get to fancy and assigning the returned value to a variable.&nbsp;&nbsp;<br><br>Now it works great.&nbsp;&nbsp;Thanks again for the tip. <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top