473,549 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Userform search (if Possible)

88 New Member
I was wondering if anyone can please help me with this task I would to create a userform that will search a workbook in excel with mulitiple sheet, it could be 5-endless worksheets The way i would like to do this is a new tab is created when a new client is add to our database and be able to seach curtain critiera such Hospital name, Contact name,services,p hone numbers(if possible)and User name (if Possible) It sounds more complacted then it seems i am going to try to attach the file and code is there anyone whom can help i will be thankful


Expand|Select|Wrap|Line Numbers
  1. [Option Explicit]
  2.  
  3. 'Module Level Variables
  4. Dim rRange As Range
  5. Dim strFind1 As String
  6. Dim strFind2 As String
  7. Dim strFind3 As String
  8.  
  9.  
  10. Private Sub ComboBox1_Change()
  11. 'Pass chosen value to String variable strFind1
  12. strFind1 = ComboBox1
  13. 'Enable ComboBox2 only if value is chosen
  14. ComboBox2.Enabled = Not strFind1 = vbNullString
  15. End Sub
  16. Private Sub ComboBox2_Change()
  17. 'Pass chosen value to String variable strFind1
  18. strFind2 = ComboBox2
  19. 'Enable ComboBox3 only if value is chosen
  20. End Sub
  21.  
  22.  
  23. Private Sub CommandButton1_Click()
  24. 'Procedure level variables
  25. Dim lCount As Long
  26. Dim lOccur As Long
  27. Dim rCell As Range
  28. Dim rCell2 As Range
  29. Dim rCell3 As Range
  30. Dim bFound As Boolean
  31.  
  32. 'At least one value, from ComboBox1 must be chosen
  33. If strFind1 & strFind2 & strFind3 = vbNullString Then
  34.    MsgBox "No items to find chosen", vbCritical
  35.    Exit Sub 'Go no further
  36. ElseIf strFind1 = vbNullString Then
  37.    MsgBox "A value from " & Label1.Caption _
  38.    & " must be chosen", vbCritical
  39.    Exit Sub 'Go no further
  40. End If
  41.  
  42. 'Clear any old entries
  43. On Error Resume Next
  44. ListBox1.Clear
  45. On Error GoTo 0
  46.  
  47. 'If String variable are empty pass the wildcard character
  48. If strFind2 = vbNullString Then strFind2 = "*"
  49. If strFind3 = vbNullString Then strFind3 = "*"
  50.  
  51. 'Set range variable to first cell in table.
  52. Set rCell = rRange.Cells(1, 1)
  53. 'Pass the number of times strFind1 occurs
  54. lOccur = WorksheetFunction.CountIf(rRange.Columns(1), strFind1)
  55.  
  56. 'Loop only as many times as strFind1 occurs
  57. For lCount = 1 To lOccur
  58. 'Set the range variable to the found cell. This is then also _
  59.  used to start the next Find from (After:=rCell)
  60.     Set rCell = rRange.Columns(1).Find(What:=strFind1, After:=rCell, _
  61.               LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
  62.               SearchDirection:=xlNext, MatchCase:=False)
  63.     'Check each find to see if strFind2 and strFind3 occur _
  64.      on the same row.
  65.     If rCell(1, 2) Like strFind2 And rCell(1, 3) Like strFind3 Then
  66.        bFound = True 'Used to not show message box for no value found.
  67.        'Add the address of the found cell and the cell on the _
  68.         same row but 2 columns to the right.
  69.        ListBox1.AddItem rCell.Address & ":" & rCell(1, 3).Address
  70.     End If
  71. Next lCount
  72.  
  73. If bFound = False Then 'No match
  74.  MsgBox "Sorry, no matches", vbOKOnly
  75. End If
  76. End Sub
  77.  
  78. Private Sub CommandButton2_Click()
  79. 'Close UserForm
  80. Unload Me
  81. End Sub
  82.  
  83.  
  84. Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  85. 'Check for range addresses
  86. If ListBox1.ListCount = 0 Then Exit Sub
  87. 'GoTo doubled clicked address
  88. Application.Goto Range(ListBox1.Text), True
  89. End Sub
  90.  
  91. Private Sub UserForm_Initialize()
  92. 'Procedure level module
  93. Dim lRows As Long
  94.  
  95. 'Set Module level range variable to CurrentRegion _
  96.  of the Selection
  97. Set rRange = Selection.CurrentRegion
  98.     If rRange.Rows.Count < 2 Then ' Only 1 row
  99.        MsgBox "Please select any cell in your table first", vbCritical
  100.        Unload Me 'Close Userform
  101.        Exit Sub
  102.     Else
  103.  
  104.     With rRange
  105.     'Set Label Captions to the Table headings
  106.         Label1.Caption = .Cells(1, 1)
  107.         Label2.Caption = .Cells(1, 2)
  108.         Label3.Caption = .Cells(1, 3)
  109.  
  110.         'Set RowSource of ComboBoxes to the appropriate columns _
  111.          inside the table
  112.        strSheet = ListBox1.List(ListBox1.ListIndex, 1)
  113.     strAddress = ListBox1.List(ListBox1.ListIndex, 2)
  114.  
  115.  
  116.     End With
  117.     End If
  118. End Sub
  119.  
  120. Private Sub UserForm_Terminate()
  121. 'Destroy Module level variables
  122. Set rRange = Nothing
  123. strFind1 = vbNullString
  124. strFind2 = vbNullString
  125. End Sub
update:
By the way the Log-n password is PLS4-Username Password PLS
Attached Files
File Type: zip Hospital Datebase.zip (510 Bytes, 90 views)
Oct 12 '11 #1
5 1695
Guido Geurs
767 Recognized Expert Contributor
Is this Office 2003?
In the ZIP is an .LNK file and not a .XLS or a .XLSM!
Oct 13 '11 #2
sandy armstrong
88 New Member
I am very new to this here is a new copy of what i need help with
Attached Files
File Type: zip Hospital Datebase - Shortcut.zip (739 Bytes, 53 views)
Oct 13 '11 #3
Guido Geurs
767 Recognized Expert Contributor
This is still a LINK to a database we don't have.
Is it possible to put some data in an Excel file and attach this file in Bytes ? (also with you form)
Because in your code there is no connection to a database, is your data already in the Excel workbook ?
Or am I wrong ?
Oct 13 '11 #4
sandy armstrong
88 New Member
This is the very beginging stages of what i am trying to accomplish I did not realize until now that if I make a change in my workbook it will also change what i posted on Bytes can i please have an email for you in order for me to forward this file to you, i cant seem to upload this correctly.
Or if you can tell me another way of getting this to you i really need help!!! and would be thankful for any guidedance in this matter.
Oct 13 '11 #5
Guido Geurs
767 Recognized Expert Contributor
Is it possible to send us an Excel file with some data (+- 100 rows of data in some sheets) (the file can't be to big !!) in a ZIP file ?
I have attached a DOC and a PDF explaining how to do this.
Attached Files
File Type: zip Bytes_manual.zip (234.1 KB, 74 views)
Oct 14 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1561
by: Continental Translations | last post by:
Not too sure if this is the correct NG, but here goes.... I am in the process of creating a website (http://www.continental-translations.com - well someone is creating it for me) and I am hoping to put an interactive userform in the website. Basically I have an MS Access Database set up so that I can pick a language pair, insert how many...
0
1661
by: szymon_k | last post by:
Hi. How to set the userform as subform of some access form? What I need to do is to insert some userform into the form, so that it will be under the same conditions of resize, move and other operations on this access form to be applied also to this userform. I just want this userform to look like (for example) some textbox, subform or object...
3
4951
by: gw.boswell | last post by:
I have created a userform with textboxes for data entry. I also have a command button that calls a second useform. A user enters certain information in the first useform but if he/she wants to do additional calculations, they use the command button to bring up the second userform and add additional information via textboxes in the second...
2
3241
by: williamyeow | last post by:
Hi i am new to excel VB. can anyone tell me how to link userform to another userform? My concept for my program I have set up a userform with a couple of option. after the user has chose the options and click next, userform2 will be activated. Thanks
1
4071
by: brenty66 | last post by:
I have a userform that is used as an interface for information stored on excel spreadsheets. The user enters bits of information into fields on the userform which are place on the corresponding worksheet. I would like to have a txtBox that is used as a search field. When the user enters a number in the field it will search through column A of...
1
328
by: Guillermo | last post by:
Hi! Is it possible to load the full-text search module for the SQLite version bundled with Python 2.5? I've tested it and the stand-alone SQLite distribution doesn't seem to include it (sqlite.load fts2), nor does Python. I'm on Windows XP.
3
11428
pod
by: pod | last post by:
Hello What I want to do is: from this workbook (thisWB), I want to access a userform's properties that are in another Workbook (toolWB) I can do this for worksheets, but I want to do it as well for the userform I have searched the help files, forums and went through all of the properties of workbooks and worksheets to no avail. I...
1
2196
by: esperanto234 | last post by:
Hi, This is the Ultimate Question!!! I already finished my program in VBA, it has a userform for filling data into Word. It has a bunch of textboxes. But people has to fill de information into the textboxes every time they open the userform. Information that is already in a databse in excel. My question is: How can i do to fill...
9
6803
by: David Wilkinson | last post by:
Hi, I am reasonably new to Excel VBA. I have written a Userform (Wizard) with a large amount of code and I am hitting the limits of the number of lines of code or the famous undocumented limit of 64K per module. In any case, I need to reduce the amount of code in the Userform module by placing some of the procedures and functions into...
1
1634
by: katie co | last post by:
Basically I want the user to open a previously saved file. I wish for my program to create a userform that asks "what file would you like to open" and I would like the user to only have to type in a keyword to search for the file. Is this possible?
0
7524
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.