Question:

Record display in the textbox/combo box frm dbase by clicking on command button in VB6?

by  |  earlier

0 LIKES UnLike

Dear Friend

I have a table named as “ient” and I can save data over there or retrieve data from there. Now I want to display data in the control boxes like textbox, combo box, date picker etc. one after another i.e. by clicking on the command button move next/move previous etc and I have used below code for move next, but it’s not working. Please help on this issue.

Dim rst1 As New ADODB.Recordset ‘ in the general declaration

Private Sub cmdnext_Click()

DBconnect ‘I have used this public sub-routine to connect with the database

If rst1.State = adStateOpen Then rst1.Close

rst1.Open "ient", cnt, adOpenDynamic, adLockOptimistic

If Not rst1.EOF() And Not rst1.BOF() Then rst1.MoveNext

With rst1

txtrefno.Text = .Fields(0)

Combo1.Text = .Fields(1)

DTPicker1.Value = .Fields(2)

cmbcustomer.Text = .Fields(3)

cmbmanufacturer.Text = .Fields(4)

txtinvoice.Text = .Fields(5)

DTPicker2.Value = .Fields(6)

End With

End Sub

Appreciate, if you would come back soon.

Regards

Pervez

 Tags:

   Report

2 ANSWERS


  1. Each time you are clicking on the next button you are opening a new recordset so you will always be showing the first record.  


  2. Assuming your connection to the ADO recordset is working, and you're actually returning some records, then I'd look at whether or not some of the fields are empty (Null) ... that's one of the most common reasons for not getting the data to populate controls.

    You should create a subroutine for testing nulls that would fill the control with some default value in the event that the field is a null value.

    Something like this:

    If IsNull (rst1.Fields(0)) Then

    ctrl.text = ""

    Else

    ctrl.Text = rst1.Fields(0)

    End If

    You can contact me through my profile if you need additional assistance.

    Good luck!

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.