I have developed a form to input data in a spreadsheet which works fine. I have added a button which should allow the user to search on a text field, in this case the field name is txtApplicationNumber. When a number is input to the field on the form and the user hits search it should display the data for this request in the form. The data starts on line 9 of the sheet called Master Table. Currently, regardless of the inputs in the field it returns the first line of data. I have been banging my head on this for a few hours and decided to ask for help.
Any quick pointers you might be able to give on using a Next and Previous button would be helpful.
The code I have for this is as follows:
Thanks in advance!
Any quick pointers you might be able to give on using a Next and Previous button would be helpful.
The code I have for this is as follows:
Code:
Private Sub cmdViewRecord_Click()
Dim totrows As Long, i As Long
Set ws2 = Sheets("Master Table")
totrows = Worksheets("Master Table").Range("B9").CurrentRegion.Rows.Count
If txtApplicationNumber.Text = "" Then
MsgBox "Search Requires an Entry in Application Number"
End If
For i = 9 To totrows
txtVendorName = ws2.Cells(i, 1)
txtApplicationNumber = ws2.Cells(i, 2)
txtApplicationName = ws2.Cells(i, 3)
txtIdentifier.Text = ws2.Cells(i, 4)
txtPortfolio.Text = ws2.Cells(i, 5)
txtWorkstream.Text = ws2.Cells(i, 6)
txtApplicationGroup.Text = ws2.Cells(i, 7)
txtSupportGroup.Text = ws2.Cells(i, 12)
txtTier.Text = ws2.Cells(i, 13)
txtOwner.Text = ws2.Cells(i, 19)
txtContractNumber.Text = ws2.Cells(i, 20)
txtContractWorkspaceNumber.Text = ws2.Cells(i, 21)
txtStatusofExecution.Text = ws2.Cells(i, 23)
txtCostCenter.Text = ws2.Cells(i, 24)
txtNov15.Text = ws2.Cells(i, 28)
txtDec15.Text = ws2.Cells(i, 29)
txtJan16.Text = ws2.Cells(i, 30)
txtFeb16.Text = ws2.Cells(i, 31)
txtMar16.Text = ws2.Cells(i, 32)
txtApr16.Text = ws2.Cells(i, 33)
txtMay16.Text = ws2.Cells(i, 34)
txtJun16.Text = ws2.Cells(i, 35)
txtJul16.Text = ws2.Cells(i, 36)
txtAug16.Text = ws2.Cells(i, 37)
txtSep16.Text = ws2.Cells(i, 38)
txtOct16.Text = ws2.Cells(i, 39)
txtNov16.Text = ws2.Cells(i, 40)
txtDec16.Text = ws2.Cells(i, 41)
txtJan17.Text = ws2.Cells(i, 42)
txtFeb17.Text = ws2.Cells(i, 43)
txtMar17.Text = ws2.Cells(i, 44)
txtApr17.Text = ws2.Cells(i, 45)
txtMay17.Text = ws2.Cells(i, 46)
txtJun17.Text = ws2.Cells(i, 47)
txtJul17.Text = ws2.Cells(i, 48)
txtAug17.Text = ws2.Cells(i, 49)
txtSep17.Text = ws2.Cells(i, 50)
txtOct17.Text = ws2.Cells(i, 51)
txtNov17.Text = ws2.Cells(i, 52)
txtDec17.Text = ws2.Cells(i, 53)
txtJan18.Text = ws2.Cells(i, 54)
txtFeb18.Text = ws2.Cells(i, 55)
txtMar18.Text = ws2.Cells(i, 56)
txtApr18.Text = ws2.Cells(i, 57)
txtMay18.Text = ws2.Cells(i, 58)
txtJun18.Text = ws2.Cells(i, 59)
txtJul18.Text = ws2.Cells(i, 60)
txtAug18.Text = ws2.Cells(i, 61)
txtSep18.Text = ws2.Cells(i, 62)
txtOct18.Text = ws2.Cells(i, 63)
txtNov18.Text = ws2.Cells(i, 64)
txtDec18.Text = ws2.Cells(i, 65)
txtJan19.Text = ws2.Cells(i, 66)
txtFeb19.Text = ws2.Cells(i, 67)
txtMar19.Text = ws2.Cells(i, 68)
txtApr19.Text = ws2.Cells(i, 69)
txtMay19.Text = ws2.Cells(i, 70)
txtJun19.Text = ws2.Cells(i, 71)
txtJul19.Text = ws2.Cells(i, 72)
txtAug19.Text = ws2.Cells(i, 73)
txtSep19.Text = ws2.Cells(i, 74)
txtOct19.Text = ws2.Cells(i, 75)
txtNov19.Text = ws2.Cells(i, 76)
txtDec19.Text = ws2.Cells(i, 77)
txtJan20.Text = ws2.Cells(i, 78)
txtFeb20.Text = ws2.Cells(i, 79)
txtMar20.Text = ws2.Cells(i, 80)
txtApr20.Text = ws2.Cells(i, 81)
txtMay20.Text = ws2.Cells(i, 82)
txtJun20.Text = ws2.Cells(i, 83)
txtJul20.Text = ws2.Cells(i, 84)
txtAug20.Text = ws2.Cells(i, 85)
txtSep20.Text = ws2.Cells(i, 86)
txtOct20.Text = ws2.Cells(i, 87)
txtNov20.Text = ws2.Cells(i, 88)
txtNov20.Text = ws2.Cells(i, 88)
txtContractTotal.Text = ws2.Cells(i, 89)
txtYear1.Text = ws2.Cells(i, 92)
txtYear2.Text = ws2.Cells(i, 93)
txtYear3.Text = ws2.Cells(i, 94)
txtYear4.Text = ws2.Cells(i, 95)
txtYear5.Text = ws2.Cells(i, 96)
Exit For
Next i
End Sub
Thanks in advance!