Stephen Manderson
asked on
Easy Problem with my code URGENT
Hi all, I cant seem to get round this even although its a very simple idea, what I am trying to do is search through a list of names and if there is more than one name then i need to another page with a flexgrid with full details of each of the names if there are more than one, but for simple sake, I just need it to show a text box. If there is only one name found then all i need is to show another text box. here is the code I am using, I have changed the requirements so that a msg box is shown if there is one name and another message is shown if there are more than one.
Private Sub CSearch(SCriteria)
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strIniFile As String
Dim criteria
Dim counter
Dim found As Boolean
strIniFile = App.Path & "\dbconnectionstrings.ini"
conn.Provider = GetFromINI("ConnectionStri ngs", "sdmpr", strIniFile)
conn.Open GetFromINI("ConnectionStri ngs", "sdmdb", strIniFile)
sqlstr = "SELECT * FROM Clients ORDER BY Surname ASC"
rs.Open sqlstr, conn, adOpenKeyset, adLockOptimistic
If cmbsearch.Text = "" Then
MsgBox "Please select a field to search", vbintormation, "Define Search Field"
Else
criteria = cmbsearch.Text
With rs
.MoveFirst
Do Until .EOF Or found
If .Fields(criteria) = SCriteria Then
counter = counter + 1
found = true <<< I know this will stop the loop here, but just an idea of what im trying to get.
Else
.MoveNext
End If
End If
Loop
If counter > 1 Then
MsgBox "found more than one name"
End If
If found = True Then
MsgBox "Found one name"
Else
MsgBox "Record not found", vbInformation, "Record Search"
.MoveFirst
End If
End With
Set rs = Nothing
conn.Close
Set conn = Nothing
End If
End Sub
Private Sub CSearch(SCriteria)
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strIniFile As String
Dim criteria
Dim counter
Dim found As Boolean
strIniFile = App.Path & "\dbconnectionstrings.ini"
conn.Provider = GetFromINI("ConnectionStri
conn.Open GetFromINI("ConnectionStri
sqlstr = "SELECT * FROM Clients ORDER BY Surname ASC"
rs.Open sqlstr, conn, adOpenKeyset, adLockOptimistic
If cmbsearch.Text = "" Then
MsgBox "Please select a field to search", vbintormation, "Define Search Field"
Else
criteria = cmbsearch.Text
With rs
.MoveFirst
Do Until .EOF Or found
If .Fields(criteria) = SCriteria Then
counter = counter + 1
found = true <<< I know this will stop the loop here, but just an idea of what im trying to get.
Else
.MoveNext
End If
End If
Loop
If counter > 1 Then
MsgBox "found more than one name"
End If
If found = True Then
MsgBox "Found one name"
Else
MsgBox "Record not found", vbInformation, "Record Search"
.MoveFirst
End If
End With
Set rs = Nothing
conn.Close
Set conn = Nothing
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks S
Private Sub CSearch(SCriteria)
...
Dim resultcount as Long
...
rs.Open sqlstr, conn, adOpenKeyset, adLockOptimistic
rs.MoveLast
resultcount = rs.Count
rs.MoveFirst
...
if resultcount >= 2 then
...
else
...
end if