0

enter image description here

Hi guys... I'm trying to make a sample program that views the records from the database like the output above. I am using visual basic 6.0 and Access... With DataControl, I'd like to view the next records of the specific ID Number, by clicking on the Next button. My problem with the code below is the records with other ID Number are appearing...

Private Sub cmdNext_Click()
    With Me.dtaInfo.Recordset
        .MoveNext

        Me.txtCash.Text = .Fields("Cash")
        Me.txtAddress.Text = .Fields("Country")
    End With
End Sub

Private Sub cmdShow_Click()
    With Me.dtaInfo.Recordset
        .Index = "idxIDNumber"
        .Seek "=", Me.txtIDNumber.Text

        Me.txtCash.Text = .Fields("Cash")
        Me.txtAddress.Text = .Fields("Country")
    End With
End Sub

Here's my records enter image description here

Aaron
  • 1,969
  • 6
  • 27
  • 47
  • Well, I can only guess here... I noticed you have duplicates in IDNumber column (e.g. B6, B4)? My guess is "other ID Number" would affect records w/ IDNumber = B6 or B4. If that's not the case, one more screenshot (w/ incorrect data) would be helpful. – Igor Turman Mar 13 '12 at 15:50
  • @IgorTurman... I mean, when I search the record with the ID Number, let say B6, all the records (Cash and Country) with this ID Number will be viewed by clicking the show button and then Next button for the next record with B6 ID Number... When I tried to search the B6, which had 2 records, the other records like B8 was appearing whenever I press the Next button, that should not be the case. – Aaron Mar 14 '12 at 00:47
  • Got you. I might be missing something, but it seems like when you use Show method you do apply filter, but when using Next method no filter is being applied. Resulting in looping through the whole recordset. But again, I am not 100% sure because I have no way to test this and VB6 w/ data control is blurry for me now :) – Igor Turman Mar 14 '12 at 15:13

1 Answers1

0

Since you are using the data control you need only bind your text boxes to it.

Right click on each of your text box controls and select "Properties". On the DataSource property set it to your data control. I.e. Data1.

Next, set the DataField property on the text box control. I.e. Cash

When you click forward/back on the data control the text box controls will be updated automatically.

If you really want to take control of the record set navigation for view / update, etc I would recommend switching to use ADO instead of DAO and using your own navigation controls instead of the data control.

Warren Rox
  • 655
  • 2
  • 8
  • 23
  • I mean, when I search the record with the ID Number, let say B6, all the records (Cash and Country) with this ID Number will be viewed by clicking the show button and then Next button for the next record with B6 ID Number... When I tried to search the B6, which had 2 records, the other records like B8 was appearing whenever I press the Next button, that should not be the case. – Aaron Mar 14 '12 at 00:51
  • Your seek statement will match on more than one record. While debugging if you check dtaInfo.Recordset.RecordCount it will confirm it. If you are trying to allow the user to search and find specific records you'll have to change your code. For example use a list box displaying each of the matched records and allow them to click the one that they were trying to find. The one that they click can be loaded and displayed in the textboxes. – Warren Rox Mar 14 '12 at 13:53