Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Matilda Hughes   on Oct 29 In MS Office Category.

  
Question Answered By: Brenda Fischer   on Oct 29

Here is my code. I am using strFind to let me search  for the value in
textbox1. I am using Case to fill in the info on the form. I would
like to change the search from just one textbox  into a search from any
textbox. I did get help from Paul but I do not know how to implement
the code. It is at the bottom of this reply. Thankyou.



Private Sub cmbFind_Click()
Dim strFind, FirstAddress As String 'what to find
Dim rSearch As Range 'range to search
Dim RecCnt As Integer
Dim i As Integer, n As Integer, e As Integer

Set rSearch = Sheet1.Range("a6", Range("q65000").End(xlUp))
strFind = Me.TextBox1.Value


Dim f As Integer
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then 'found it
c.Select
With Me 'load entry to form
.ComboBox1.Value = c.Offset(, 7).Value
.ComboBox2.Value = c.Offset(, 9).Value
.ComboBox3.Value = c.Offset(, 13).Value
.ComboBox4.Value = c.Offset(0, 14).Value
.ComboBox5.Value = c.Offset(, 11).Value
For n = 1 To 12
Select Case n
Case 1 To 7
.Controls("TextBox" & n).Value =
c.Offset(i, n - 1).Value
Case 8
.Controls("TextBox" & n).Value =
c.Offset(i, 10).Value
Case 9
.Controls("TextBox" & n).Value =
c.Offset(i, 12).Value
Case 10
.Controls("TextBox" & n).Value =
c.Offset(i, 8).Value
Case 11 To 12
.Controls("TextBox" & n).Value =
c.Offset(i, n + 4).Value
End Select
Next
.cmbAmend.Enabled = True 'allow amendment or
.cmbDelete.Enabled = True 'allow record deletion
.cmbAdd.Enabled = False 'don't want to duplicate
record
f = 0
End With
FirstAddress = c.Address
Do
f = f + 1 'count number of matching records
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
If f > 1 Then
MsgBox "There are " & f & " instances of " & strFind
Me.Height = 456
End If
Else: MsgBox strFind & " not listed" 'search failed
End If
End With
End Sub




hdr_row = 6
RecCnt = application.worksheetfunction.counta(range(cells(hdr_Row +
1,1),cells(65000,1) 'or whatever the range is for I = 1 to RecCnt
'(keep in mind that this is a count of records, not rows!
SelectFlag = false
if (txtbox1.value = "") or (instr(1,cells(i,1),textbox1.value) > 0)
then
if (txtbox2.value = "") or (instr(1,cells(i,2),textbox2.value) >
0) then
selectflag = true
end if
end if
if selectflag then
'Add line to ListBox
end if
next I


Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Using Case to do a multi-textbox search Or get search suggestion and latest updates.


Tagged: