I have a form in MS Access 2010 That displays contract information. There is a subform that displays the customer information from that contract. I have a command button on the form so that if the user doesn't know the contract number they can find all contracts related to a specific person. The command button displays 2 prompts 1 for the last name and 1 for the first name with a minimum of 3 characters. It then builds a query and gets all of the contractID's related to the matching people. Code Below:
Code:
Private Sub cmd_find_customer_Click()
Dim lastname as string, firstname as string, tmpstr as string
Dim strsql as string, rs as new adodb.recordset
lastname = Inputbox("Please Enter the last name (Minimum of 3 characters)","Last Name"
firstname = Inputbox("Please enter the first name ","First Name") 'There is no min on the first name just in case they want all with the same lastname
tmpstr = "" 'Clear the tmpstr
strsql = "Select contractID from tbl_customer_contract_link inner join tbl_customer on tbl_customer_contract_link.customerid = tbl_customer.customerid " & _
"Where tbl_customer.lastname Like ""*" & lastname & "*"" and tbl_customer.firstname like ""*" & firstname & "*"""
rs.open strsql,currentproject.connection,adopenforwardonly,adlockreadonly
do until rs.eof
tmpstr = tmpstr & rs!contractID & ","
rs.movenext
loop
If tmpstr > 1 Then
tmpstr = left(tmpstr,len(tmpstr)-1)
me.filter = "ContractID In (" & tmpstr & ")"
me.filteron = true
End if
rs.close
set rs = nothing
End sub
When I click on the button I get the 2 prompts put in the data for the prompts but when the code executes I get 0 records. If I put in a breakpoint at the rs.open command pull the strsql string out and put it into a query I get the expected records. Executing in the code returns 0 records????
Anybody have an idea what I'm missing?