Results 1 to 7 of 7

Thread: Recordset SQL MSAccess question rather confused? *RESOLVED*

Threaded View

  1. #1

    Thread Starter
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290

    Recordset SQL MSAccess question rather confused? *RESOLVED*

    I have a search/find dialog box that pops up when the client/user wants to search the records in the membership table in the database. the client/user can search by member id, home phone, last name, and driver license. the client/user can type in part of a search value followed by an asterisk "*". the value is passed to a function and a SQL statement is created using a LIKE search. This is being performed on an access database. I can get the query to work from within access using the query design view. however, i cannot get the SQL statement to work from within my program when i open a recordset with it. it doesn't fail but it does not return any records. i hope this make sense. here is the SQL statement that i create the SQL is then passed to a class function. any help will be greatly appreciated. thanks in advance.


    VB Code:
    1. Public Function FindMember(ByVal sSearchVal As String, ByVal sField As String) As Long
    2.     Dim sSQL    As String
    3.     Dim lCnt    As Long
    4.    
    5.     'Determine if the recordset has been created.
    6.     If rs Is Nothing Then
    7.         Set rs = New ADODB.Recordset
    8.     End If
    9.    
    10.     'Determine if the recordset has been opened.
    11.     If rs.State = adStateOpen Then
    12.         rs.Close
    13.     End If
    14.    
    15.     'Determine if the value being searched for has an astrics
    16.     'in the string.
    17.     If InStr(sSearchVal, "*") Then
    18.         'If there is an astrics perform a SQL LIKE query.
    19.         sSQL = "SELECT * FROM members WHERE " & sField & " LIKE '" & UCase(sSearchVal) & "'"
    20.     Else
    21.         'If there is no astrics perform a normal SQL SELECT query.
    22.         sSQL = "SELECT * FROM members WHERE " & sField & " = '" & UCase(sSearchVal) & "'"
    23.     End If
    24.    
    25.     'Get the member data based on the SQL statement.
    26.     Call GetMemberData(sSQL)
    27.    
    28.     'Get the number of records found if any.
    29.     lCnt = cDB.RecCount(rs)
    30.     If lCnt <= 1 Then
    31.         'If the record count is 1 or less there is no need to use
    32.         'the mover buttons.
    33.         Call DisEnableMemMoverButtons(False, False, False, False, frmMembers)
    34.     Else
    35.         'More then 1 record enable all mover buttons.
    36.         Call DisEnableMemMoverButtons(True, True, True, True, frmMembers)
    37.     End If
    38.    
    39.     FindMember = lCnt
    40. End Function
    Last edited by Virus00110; Jun 10th, 2003 at 01:44 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width