Hanging Process?

acombest

Board Regular
Joined
May 8, 2017
Messages
136
Hello,
I have built an inventory program for our pharmacy at work. I have little to no experience with coding and I kind of pieced it together and it is starting to come together. The issue I am currently having is periodically the program will stop working, in that the enter button not longer returns, the "exact match" of lists boxes stop responding, and the code for the a specific textbox stops working. I can't upload the file because I'm at work. Again I am no coder and I apologize in advance.

Code:
If KeyCode = 13 And Len(TextBox7.Text) > 6 Then
Dim v As Long, Z As Long, i As Long, P As Long, F As Long, U As Long, match As Long, match2 As Long, B As Long, match3 As Long
Dim Db As Worksheet, Fl As Worksheet, Sr As Worksheet, Us As Worksheet
Set Db = Sheets("Database")
Set Fl = Sheets("Facility List")
Set Pl = Sheets("Pref List")
Set Sr = Sheets("Search")
Set Us = Sheets("Users")
match = 0
match2 = 0
Dim find As String
Dim stick As String
Dim stick2 As String
find = Replace(TextBox7.Text, "-", "")
If Len(find) > 8 Then
For v = 2 To Db.Cells(Rows.Count, "A").End(xlUp).Row
If find = Replace(Db.Cells(v, 2).Value, "-", "") Or find = Db.Cells(v, 3).Value Then
ListBox4.backcolor = vbGreen
match = match + 1
stick = v
End If
Next v
If match = 0 Then
For i = 2 To Db.Cells(Rows.Count, "A").End(xlUp).Row
If Len(TextBox7.Text) > 8 And InStr(1, find, Replace(Db.Cells(i, 2).Value, "-", "")) And Db.Cells(i, 2).Value <> "" Or Len(TextBox7.Text) > 8 And InStr(1, find, Db.Cells(i, 3).Value) And Db.Cells(i, 3).Value <> "" Or Len(TextBox7.Text) > 7 And InStr(1, Db.Cells(i, 3).Value, find) And Db.Cells(i, 3).Value <> "" Then
ListBox4.backcolor = vbYellow
match = match + 1
stick = i
End If
Next i
End If
If match > 0 Then
ElseIf match = 0 Then
With ListBox17
.AddItem find
TextBox7.Text = ""
TextBox7.SetFocus
End With
Exit Sub
End If
For P = 2 To Pl.Cells(Rows.Count, "D").End(xlUp).Row
If Replace(Db.Cells(stick, 1).Value, " ", "") = Replace(Pl.Cells(P, 4).Value, " ", "") And Db.Cells(stick, 4).Value = Pl.Cells(P, 9).Value Then
match2 = match2 + 1
stick2 = P
backcolor = Pl.Cells(P, 4).Interior.Color
End If
Next P
For B = 2 To Pl.Cells(Rows.Count, "D").End(xlUp).Row
If Replace(Db.Cells(stick, 1).Value, " ", "") = Replace(Pl.Cells(B, 4).Value, " ", "") And match > 0 And match2 = 0 Then
match2 = match2 + 1
stick2 = B
backcolor = Pl.Cells(P, 4).Interior.Color
End If
Next B
k = Sr.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row
If match > 0 And match2 > 0 Then
        Sr.Range(Sr.Cells(k, 1), Sr.Cells(k, 15)).Value = _
        Db.Range(Db.Cells(stick, 1), Db.Cells(stick, 15)).Value
        Sr.Cells(k, 7).Interior.Color = backcolor
        If Pl.Cells(stick2, 8).Value = "X" Or Pl.Cells(stick2, 8).Value = "~" Or Pl.Cells(stick2, 8).Value = "0" Or Pl.Cells(stick2, 7).Value = "" Or backcolor <> "15204351" And backcolor <> "7950803" Then
        ListBox4.backcolor = vbBlue
        Sr.Cells(k, 8).Value = "NF"
        Sr.Cells(k, 7).Value = "NF"
        ElseIf stick2 <> "" Then
        Sr.Cells(k, 8).Value = Pl.Cells(stick2, 7).Value
        Sr.Cells(k, 7).Value = Pl.Cells(stick2, 8).Value
        End If
ElseIf match > 0 And match2 = 0 Then 'Not on facility list
        Sr.Range(Sr.Cells(k, 1), Sr.Cells(k, 15)).Value = _
        Db.Range(Db.Cells(stick, 1), Db.Cells(stick, 15)).Value
        ListBox4.backcolor = vbBlue
        Sr.Cells(k, 8).Value = "NF"
        Sr.Cells(k, 7).Value = "NF"
        End If
        Sheets("Search").Activate
        ListBox4.RowSource = Sheets("Search").Range("A2:O2", Cells(Rows.Count, "A").End(xlUp)).Address
        ListBox4.ColumnHeads = True
        Sheets("Database").Activate
                    TextBox7.Text = ""
                    TextBox7.SetFocus
                    End If
                    End If
We use a scanner to scan the barcode of an item in to textbox 7. The item searches our database sheet for a match. It then checks our preferred list of items to see if it is something we are supposed to carry and then checks to see how much should be ordered and then it adds it to the batch order in a separate listbox.
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,912
Messages
6,175,348
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top