Results 1 to 2 of 2
  1. #1
    mnsemple83 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    40

    Creating a form in VBA that will display search results in DS view

    This question may have been answered in an earlier thread but...

    I am trying to create a form in VBA for Access that will return the results of a search in Datasheet view. Here is the code that I have written:



    Code:
        If Len(cmbSearchField) = 0 Or IsNull(cmbSearchField) = True Then
            MsgBox "You must select a field to search."
     
        ElseIf Len(txtSearchTxt) = 0 Or IsNull(txtSearchTxt) = True Then
            MsgBox "You must enter a search string."
     
        Else
            Dim frmResults As Form
            Set frmResults = CreateForm
     
            'Generate search criteria
            GCriteria = cmbSearchField.Value & " LIKE '*" & txtSearchTxt & "*'"
     
            'Filter frmDatabaseMainScreen_2 based on search criteria
            'Form_frmDatabaseMainScreen_2.RecordSource = "select * from tblPatients where " & GCriteria
            'Form_frmDatabaseMainScreen_2.Caption = "Database (" & cmbSearchField.Value & " contains '*" & txtSearchTxt & "*')"
            frmResults.RecordSource = "select * from tblPatients where " & GCriteria
            frmResults.Caption = "Database (" & frmDatabaseMainScreen_2.cmbSearchField.Value & " contains '*" & frmDatabaseMainScreen_2.txtSearchTxt & "*')"
     
            DoCmd.OpenForm "frmResults", acFormDS
    Any suggestions or answers?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I'm assuming it doesn't work?

    You don't really say if this is a problem or if you're looking for a better solution or if you're getting an error message or anything.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-01-2010, 11:10 AM
  2. Query results visible in a form view in Access
    By pawelek022 in forum Forms
    Replies: 0
    Last Post: 11-30-2010, 01:25 PM
  3. Replies: 4
    Last Post: 01-11-2010, 11:41 PM
  4. Tabs will not display in Form View
    By dharriet in forum Forms
    Replies: 1
    Last Post: 06-29-2009, 08:28 AM
  5. Form to display results
    By Zholt in forum Forms
    Replies: 9
    Last Post: 05-07-2009, 10:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums