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

add records to a listbox on a new form 1

Status
Not open for further replies.

infoscion

Technical User
Jan 21, 2005
50
0
0
US
Hi All:
I am working on a way to display results of a search. The user enters the search criteria in the form named form1. Depending upon the entry made often dictated by the location of the wild card charcter a set of different SQL statements are executed. I was wondering as to how do I transfer the results of a query to the list box in the second from 'search names'for display purposes. I have attempted to do this through the following code. When I execute this code there are no execution errors however, the code does not achieve anything. My question is as to how do I get the values displayed on the list box of the form 'searchnames.' Do I need to manipulate the record type or the record source property of the list box? Is there soemthing else that I need to do? Please, your ideas are solicited.

****strafter, strbefore and strnull are different strings storing parts of the search text depending on the location of the wild card character(e.g. strafter refers to the '*' at the end of the search text, strbefore refers to the '*' at the beginning of the search text and strnull refers to the search text if there is no wild card character)
Thanks
Info
*************************************************
If Mid(mystring, 1, 1) = "*" Then
strbefore = Mid(mystring, 2, (Len(mystring)))
strafter = vbNullString
strnull = vbNullString
strSQL = "SELECT * FROM directory WHERE last_name LIKE '" & strafter & strbefore & strnull & "%';"

'open the recordset
'rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic
DoCmd.OpenForm "searchnames"
Set f = Screen.ActiveForm
'f!SelectCode.RowSource = "SELECT * FROM directory WHERE last_name LIKE '" & strbefore & strafter & strnull & "%';"
Forms!searchnames!SelectCode.RowSourceType = strSQL
Forms!searchnames!SelectCode.RowSource = "SELECT * FROM directory WHERE last_name LIKE '" & strafter & strbefore & strnull & "%';"
MsgBox (Forms!searchnames!SelectCode.RowSource & "2")
MsgBox (f!SelectCode.RowSource & "3")
,***********************
 
Why not simply this ?
strSQL = "SELECT * FROM directory WHERE last_name LIKE '" & mystring & "*'"
DoCmd.OpenForm "searchnames"
Forms!searchnames!SelectCode.RowSource = strSQL


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV:
Thank you for your tips. What is required is that you need to include the "AddItem" to the following statement.
Forms!searchnames!SelectCode.RowSource = strSQL

The correct syntax to achive this is
Forms!searchnames!SelectCode AddItem strSQL
Having included the AddItem term, the code runs error free and does what it is supposed to be doing.

Again, thnak you for your help.
Regards,
Info
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top