TitusandNero
New Member
- Joined
- Mar 17, 2016
- Messages
- 26
Hi there,
From watching YouTube videos and reading advice on this website I've managed to build myself a pretty snazzy database with a multi-page Userform. It's all working perfectly well however, I have one command button left to code and I can't find anything on the net that does what I want it to do. On the Userform is a 'Text Box' and next to that is a 'Search' Command Button - enter in the unique ID in the text box, click the search command button and hey presto it populates the Userform. All good so far. However, I would like to give the end user another search option, this time by Membership Number, just in case they can't remember the unique ID. The problem I'm having is that there maybe more than one entry under that Membership Number. I'm not sure of the terminology but I'm guessing I need a 'loop' in my coding? So that every time I click on this 'Search' command button it goes to the next record with that Membership Number, and the next , and the next, looping back on itself to the start. If there is only one record found then I also want it to pop up a message box saying something like 'No additional records found'. Can someone help me please? Here is my coding for the Search command button:
Private Sub cmdSMN1_Click()
txbFN1.Text = ""
txbSN1.Text = ""
txbMN1.Text = ""
txbTN1.Text = ""
txbEM1.Text = ""
txbEMP1.Text = ""
txbDEPT1.Text = ""
txbCN1.Text = ""
txbCD1.Text = ""
txbCC1.Text = ""
cbxREPTEL1.Text = ""
txbNOTES1.Text = ""
cxbxET1.Value = "False"
cxbxDC1.Value = "False"
cxbxPI1.Value = "False"
cmdCLR1.Caption = "Clear"
TRows = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
For i = 2 To TRows
If Val(Strings.Trim(Worksheets("Data").Cells(i, 2).Value)) = Val(Strings.Trim(tbMN1.Text)) Then
txbFN1.Text = Worksheets("Data").Cells(i, 4).Value
txbSN1.Text = Worksheets("Data").Cells(i, 3).Value
txbMN1.Text = Worksheets("Data").Cells(i, 2).Value
LDD1.Date = Worksheets("Data").Cells(i, 5).Value
txbTN1.Text = Worksheets("Data").Cells(i, 6).Value
txbEM1.Text = Worksheets("Data").Cells(i, 7).Value
txbEMP1.Text = Worksheets("Data").Cells(i, 8).Value
txbDEPT1.Text = Worksheets("Data").Cells(i, 9).Value
txbCN1.Text = Worksheets("Data").Cells(i, 1).Value
lbxCT1.Value = Worksheets("Data").Cells(i, 10).Value
txbCD1.Value = Worksheets("Data").Cells(i, 11).Value
LDD2.Date = Worksheets("Data").Cells(i, 12).Value
LDD3.Date = Worksheets("Data").Cells(i, 13).Value
txbCC1.Text = Worksheets("Data").Cells(i, 14).Value
cbxREPTEL1.Text = Worksheets("Data").Cells(i, 15).Value
cxbxET1.Value = Worksheets("Data").Cells(i, 16).Value
cxbxDC1.Value = Worksheets("Data").Cells(i, 17).Value
cxbxPI1.Value = Worksheets("Data").Cells(i, 18).Value
txbNOTES1.Text = Worksheets("data").Cells(i, 19).Value
tbSN1.Value = ""
tbCN1.Value = ""
Exit For
End If
Next i
If txbMN1.Text = "" Then
End If
End Sub
From watching YouTube videos and reading advice on this website I've managed to build myself a pretty snazzy database with a multi-page Userform. It's all working perfectly well however, I have one command button left to code and I can't find anything on the net that does what I want it to do. On the Userform is a 'Text Box' and next to that is a 'Search' Command Button - enter in the unique ID in the text box, click the search command button and hey presto it populates the Userform. All good so far. However, I would like to give the end user another search option, this time by Membership Number, just in case they can't remember the unique ID. The problem I'm having is that there maybe more than one entry under that Membership Number. I'm not sure of the terminology but I'm guessing I need a 'loop' in my coding? So that every time I click on this 'Search' command button it goes to the next record with that Membership Number, and the next , and the next, looping back on itself to the start. If there is only one record found then I also want it to pop up a message box saying something like 'No additional records found'. Can someone help me please? Here is my coding for the Search command button:
Private Sub cmdSMN1_Click()
txbFN1.Text = ""
txbSN1.Text = ""
txbMN1.Text = ""
txbTN1.Text = ""
txbEM1.Text = ""
txbEMP1.Text = ""
txbDEPT1.Text = ""
txbCN1.Text = ""
txbCD1.Text = ""
txbCC1.Text = ""
cbxREPTEL1.Text = ""
txbNOTES1.Text = ""
cxbxET1.Value = "False"
cxbxDC1.Value = "False"
cxbxPI1.Value = "False"
cmdCLR1.Caption = "Clear"
TRows = Worksheets("Data").Range("A1").CurrentRegion.Rows.Count
For i = 2 To TRows
If Val(Strings.Trim(Worksheets("Data").Cells(i, 2).Value)) = Val(Strings.Trim(tbMN1.Text)) Then
txbFN1.Text = Worksheets("Data").Cells(i, 4).Value
txbSN1.Text = Worksheets("Data").Cells(i, 3).Value
txbMN1.Text = Worksheets("Data").Cells(i, 2).Value
LDD1.Date = Worksheets("Data").Cells(i, 5).Value
txbTN1.Text = Worksheets("Data").Cells(i, 6).Value
txbEM1.Text = Worksheets("Data").Cells(i, 7).Value
txbEMP1.Text = Worksheets("Data").Cells(i, 8).Value
txbDEPT1.Text = Worksheets("Data").Cells(i, 9).Value
txbCN1.Text = Worksheets("Data").Cells(i, 1).Value
lbxCT1.Value = Worksheets("Data").Cells(i, 10).Value
txbCD1.Value = Worksheets("Data").Cells(i, 11).Value
LDD2.Date = Worksheets("Data").Cells(i, 12).Value
LDD3.Date = Worksheets("Data").Cells(i, 13).Value
txbCC1.Text = Worksheets("Data").Cells(i, 14).Value
cbxREPTEL1.Text = Worksheets("Data").Cells(i, 15).Value
cxbxET1.Value = Worksheets("Data").Cells(i, 16).Value
cxbxDC1.Value = Worksheets("Data").Cells(i, 17).Value
cxbxPI1.Value = Worksheets("Data").Cells(i, 18).Value
txbNOTES1.Text = Worksheets("data").Cells(i, 19).Value
tbSN1.Value = ""
tbCN1.Value = ""
Exit For
End If
Next i
If txbMN1.Text = "" Then
End If
End Sub