+ Reply to Thread
Results 1 to 5 of 5

User Form - search database

Hybrid View

  1. #1
    Registered User
    Join Date
    03-04-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    48

    Exclamation User Form - search database

    Hope this makes sense, I have a database already in place that contains personal information for a variety of individuals. I'm trying to allow an option to search the database for birthdays. I have a simple user form set up, with a drop down box to select the month of the year, on cmdclick, I want it to search the database for anyone with a birthday in the month and produce a list. Not sure if it's a big deal, but the drop down box is text entry (i.e. January etc...) but the database is numerical entry (i.e. 1/1/1980)

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: User Form - search database

    Not sure if it's a big deal, but the drop down box is text entry (i.e. January etc...) but the database is numerical entry (i.e. 1/1/1980)
    Huge deal. A sample workbook showing your formats and column/row locations would have been more helpful. I am going to assume on a lot of things. If it doesn't work it is because one of my many assumptions/guesses was wrong. Best of luck.

    Private Sub SearchButton1_Click()
    Dim ws As Worksheet:    Set ws = Sheets("Sheet1")
    Dim rDates As Range, rCell As Range
    Dim str As String
    Dim iMonth As Integer
    
    Set rDates = ws.Range("A2:A" & ws.Range("A" & Rows.Count).End(xlUp).Row)
    
    Select Case ComboBox1.Value
        Case Is = "January"
            iMonth = 1
        Case Is = "February"
            iMonth = 2
        Case Is = "March"
            iMonth = 3
        Case Is = "April"
            iMonth = 4
        'etc
        'etc
        'etc
    End Select
    
    For Each rCell In rDates
        If Len(rCell) <> 0 And Month(rCell.Value) = iMonth Then
            If str = "" Then
                str = rCell.Offset(0, 1) 'names in column B
            Else
                str = str & Chr(10) & rCell.Offset(0, 1)
            End If
        End If
    Next rCell
    
    MsgBox str
    str = ""
    
    End Sub

  3. #3
    Registered User
    Join Date
    03-04-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    48

    Re: User Form - search database

    Sorry for the delay, I've attached a sample file. The goal is to select the birthday report, pick a month from the drop down and have it run a report showing employees with birhdays in that month.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-04-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    48

    Re: User Form - search database

    With some small modifications to account for my lack of a sample workbook, stnkynts' suggestion did the trick as far as getting the corresponding names to appear in a message box. Thank you!

    I'm trying to adjust that message box to allow the user to export the list to another workbook if required, but I can't seem to get it quite right. Below is the sample code:


    HTML Code: 

  5. #5
    Registered User
    Join Date
    03-04-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    48

    Re: User Form - search database

    UPDATE

    Finally figured out how to get it to respond to the selection, I hadn't properly declared the response, new problem seems to be one after the other....

    It's exported the entire contents of the string into a single cell; how to break it back up to list properly?

    HTML Code: 

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] User Form to execute search and return all values to the user form for editing
    By allwrighty in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-11-2013, 10:40 PM
  2. how to use VBA to search and return search result in the user form
    By pearlynie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2013, 07:58 AM
  3. User Form to remove data from a database
    By Badvgood in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-12-2010, 05:21 AM
  4. Database Search Form Help?
    By Rumish8086 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-11-2006, 03:45 PM
  5. [SOLVED] User Form and Database Queries
    By Moshe Nitzani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-02-2005, 02:00 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1