D
doodle
Greetings all.
windows xp.
xl97.
Is there a way to show and refresh a listbox while the code is running
that updates it? I have a search form that allows a user to enter a
part number or part description and search for first match or all
matches.
if the user selects the part description and chooses to search for all
matches, I would like for the listbox to appear on the form and update
as the records appear in the temp table. I would then like to add a
command that would allow the user to stop the search if they see what
they need appear in the listbox.
Any help would be appreciated.
-doodle
My code:
Private Sub cmdSearch2_Click()
'On Error GoTo errClear
Dim i As String
i = frmPartsList.txtSearchCriteria.Text
frmPartsList.lblGetHCode.Visible = False
frmPartsList.lblHCode.Visible = False
frmPartsList.lblHCode2.Visible = False
frmPartsList.lblPart.Visible = False
frmPartsList.lblPartNum.Visible = False
frmPartsList.lblPartNum2.Visible = False
frmPartsList.lstParts.Visible = False
'Clears previous temp table
Sheets("Data").Range("GO6:GQ65536").ClearContents
Select Case cmbSearchBy
Case Is = "Product Description" 'If searching by desription
Sheets("Data").Select
LastRow = Cells(Rows.Count, "gm").End(xlUp).Row
With Worksheets("Data").Range("gm6:gm" & LastRow) 'with
descrip column
Set C = .Find(What:=i, LookIn:=xlValues,
lookat:=xlPart) 'find search text
If Not C Is Nothing Then
firstAddress = C.Address
Do 'Keep looking until found all
' Update my temp table with results
Set myRow =
Sheets("Data").Range("GO65536").End(xlUp)
frmPartsList.Caption = "Searching... " &
(myRow.Row - 4) & " matches found so far..."
myRow.Offset(1, 0).Value =
Range(C.Address).Offset(0, -2).Text
myRow.Offset(1, 1).Value =
Range(C.Address).Offset(0, -1).Text
myRow.Offset(1, 2).Value =
Range(C.Address).Text
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <>
firstAddress
End If
End With
Case "Part Number" 'same as code above except looking at number
column
Sheets("Data").Select
LastRow = Cells(Rows.Count, "gm").End(xlUp).Row
With Worksheets("Data").Range("gm6:gm" & LastRow) 'with
descrip column
Set C = .Find(What:=i, LookIn:=xlValues,
lookat:=xlPart)
If Not C Is Nothing Then
firstAddress = C.Address
Do
frmPartsList.Caption = "Searching... " & (myRow.Row
- 4) & " matches found so far..."
Set myRow =
Sheets("Data").Range("GO65536").End(xlUp)
myRow.Offset(1, 2).Value =
Range(C.Address).Offset(0, 2).Text
myRow.Offset(1, 1).Value =
Range(C.Address).Offset(0, 1).Text
myRow.Offset(1, 0).Value =
Range(C.Address).Text
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <>
firstAddress
End If
End With
End Select
If C Is Nothing Then MsgBox Prompt:="There are no parts listed" & _
" that match your search.", Buttons:=vbOKOnly
If Not C Is Nothing Then frmPartsList.lstParts.Visible = True
If Not C Is Nothing Then frmPartsList.lblPartNum.Visible = True
If Not C Is Nothing Then frmPartsList.lblPartNum2.Visible = True
If Not C Is Nothing Then frmPartsList.lblHCode.Visible = True
If Not C Is Nothing Then frmPartsList.lblHCode2.Visible = True
If Not C Is Nothing Then frmPartsList.lblPart.Visible = True
LastRow2 = Cells(Rows.Count, "go").End(xlUp).Row
frmPartsList.lstParts.RowSource = Sheets("Data").Range("go6:gq" &
LastRow2).Address
frmPartsList.Caption = "Parts List Search"
Sheets("FrontPage").Select
Exit Sub
errClear:
Sheets("FrontPage").Select
frmPartsList.Caption = "Parts List Search"
End Sub
windows xp.
xl97.
Is there a way to show and refresh a listbox while the code is running
that updates it? I have a search form that allows a user to enter a
part number or part description and search for first match or all
matches.
if the user selects the part description and chooses to search for all
matches, I would like for the listbox to appear on the form and update
as the records appear in the temp table. I would then like to add a
command that would allow the user to stop the search if they see what
they need appear in the listbox.
Any help would be appreciated.
-doodle
My code:
Private Sub cmdSearch2_Click()
'On Error GoTo errClear
Dim i As String
i = frmPartsList.txtSearchCriteria.Text
frmPartsList.lblGetHCode.Visible = False
frmPartsList.lblHCode.Visible = False
frmPartsList.lblHCode2.Visible = False
frmPartsList.lblPart.Visible = False
frmPartsList.lblPartNum.Visible = False
frmPartsList.lblPartNum2.Visible = False
frmPartsList.lstParts.Visible = False
'Clears previous temp table
Sheets("Data").Range("GO6:GQ65536").ClearContents
Select Case cmbSearchBy
Case Is = "Product Description" 'If searching by desription
Sheets("Data").Select
LastRow = Cells(Rows.Count, "gm").End(xlUp).Row
With Worksheets("Data").Range("gm6:gm" & LastRow) 'with
descrip column
Set C = .Find(What:=i, LookIn:=xlValues,
lookat:=xlPart) 'find search text
If Not C Is Nothing Then
firstAddress = C.Address
Do 'Keep looking until found all
' Update my temp table with results
Set myRow =
Sheets("Data").Range("GO65536").End(xlUp)
frmPartsList.Caption = "Searching... " &
(myRow.Row - 4) & " matches found so far..."
myRow.Offset(1, 0).Value =
Range(C.Address).Offset(0, -2).Text
myRow.Offset(1, 1).Value =
Range(C.Address).Offset(0, -1).Text
myRow.Offset(1, 2).Value =
Range(C.Address).Text
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <>
firstAddress
End If
End With
Case "Part Number" 'same as code above except looking at number
column
Sheets("Data").Select
LastRow = Cells(Rows.Count, "gm").End(xlUp).Row
With Worksheets("Data").Range("gm6:gm" & LastRow) 'with
descrip column
Set C = .Find(What:=i, LookIn:=xlValues,
lookat:=xlPart)
If Not C Is Nothing Then
firstAddress = C.Address
Do
frmPartsList.Caption = "Searching... " & (myRow.Row
- 4) & " matches found so far..."
Set myRow =
Sheets("Data").Range("GO65536").End(xlUp)
myRow.Offset(1, 2).Value =
Range(C.Address).Offset(0, 2).Text
myRow.Offset(1, 1).Value =
Range(C.Address).Offset(0, 1).Text
myRow.Offset(1, 0).Value =
Range(C.Address).Text
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <>
firstAddress
End If
End With
End Select
If C Is Nothing Then MsgBox Prompt:="There are no parts listed" & _
" that match your search.", Buttons:=vbOKOnly
If Not C Is Nothing Then frmPartsList.lstParts.Visible = True
If Not C Is Nothing Then frmPartsList.lblPartNum.Visible = True
If Not C Is Nothing Then frmPartsList.lblPartNum2.Visible = True
If Not C Is Nothing Then frmPartsList.lblHCode.Visible = True
If Not C Is Nothing Then frmPartsList.lblHCode2.Visible = True
If Not C Is Nothing Then frmPartsList.lblPart.Visible = True
LastRow2 = Cells(Rows.Count, "go").End(xlUp).Row
frmPartsList.lstParts.RowSource = Sheets("Data").Range("go6:gq" &
LastRow2).Address
frmPartsList.Caption = "Parts List Search"
Sheets("FrontPage").Select
Exit Sub
errClear:
Sheets("FrontPage").Select
frmPartsList.Caption = "Parts List Search"
End Sub