Hi, I need to validate a text input with the rest of the data inside excel file. The following is my code.
It just read the text input and only execute data in row 1 only instead of searching other model's data. Any suggestion where did the code goes wrong?
Your help is much appreciated. Thank you.

Private Sub cmdGo_Click()
Dim Model As String
Dim D1 As String
Dim D2 As String
Dim D3 As String
Dim D4 As String
Dim D5 As String
Dim D6 As String
Dim D7 As String
Dim D8 As String
Dim D9 As String
Dim D10 As String

BMV700.Data1.Refresh
Model = txtModel_a.Text
Model = txtModel_b.Text

D1 = txt1(0).Text
D1 = txt2(0).Text
D2 = txt1(1).Text
D2 = txt2(1).Text
D3 = txt1(2).Text
D3 = txt2(2).Text
D4 = txt1(3).Text
D4 = txt2(3).Text
D5 = txt1(4).Text
D5 = txt2(4).Text
D6 = txt1(5).Text
D6 = txt2(5).Text
D7 = txt1(6).Text
D7 = txt2(6).Text
D8 = txt1(7).Text
D8 = txt2(7).Text
D9 = txt1(8).Text
D9 = txt2(8).Text
D10 = txt1(9).Text
D10 = txt2(9).Text

Do Until BMV700.Data1.Recordset.EOF
If BMV700.Data1.Recordset.Fields("Model").Value = Model Then
txtModel_b.Text = BMV700.Data1.Recordset.Fields("Model")
txt1(0).Text = BMV700.Data1.Recordset.Fields("D1")
txt2(0).Text = BMV700.Data1.Recordset.Fields("D1")
txt1(1).Text = BMV700.Data1.Recordset.Fields("D2")
txt2(1).Text = BMV700.Data1.Recordset.Fields("D2")
txt1(2).Text = BMV700.Data1.Recordset.Fields("D3")
txt2(2).Text = BMV700.Data1.Recordset.Fields("D3")
txt1(3).Text = BMV700.Data1.Recordset.Fields("D4")
txt2(3).Text = BMV700.Data1.Recordset.Fields("D4")
txt1(4).Text = BMV700.Data1.Recordset.Fields("D5")
txt2(4).Text = BMV700.Data1.Recordset.Fields("D5")
txt1(5).Text = BMV700.Data1.Recordset.Fields("D6")
txt2(5).Text = BMV700.Data1.Recordset.Fields("D6")
txt1(6).Text = BMV700.Data1.Recordset.Fields("D7")
txt2(6).Text = BMV700.Data1.Recordset.Fields("D7")
txt1(7).Text = BMV700.Data1.Recordset.Fields("D8")
txt2(7).Text = BMV700.Data1.Recordset.Fields("D8")
txt1(8).Text = BMV700.Data1.Recordset.Fields("D9")
txt2(8).Text = BMV700.Data1.Recordset.Fields("D9")
txt1(9).Text = BMV700.Data1.Recordset.Fields("D10")
txt2(9).Text = BMV700.Data1.Recordset.Fields("D10")
Exit Do
Else
BMV700.Data1.Recordset.MoveNext
End If
Loop

Msg = MsgBox("Invalid model, try again!", vbOKOnly + vbExclamation)
If (Msg = 1) Then
BMV700.Show
txtModel_a.Text = ""
txtModel_b.Text = ""
For i = 0 To 9
txt1(i).Text = ""
txt2(i).Text = ""
Next
End If

End Sub

Recommended Answers

All 3 Replies

Hi forget to state that currently I am working with VB6.
I am a newbie and working for a school project actually.
Thank you for ur help... :)

Line 18 and 19(and following) What is the purpose of

D1 = txt1(0).Text
D1 = txt2(0).Text

You set a variable D1 to something and immediately to something else.
BTW whenever you see something like D1,D2,D3,D4 etc. you should turn this into an array.

Thanks for ur respond @ddanbe.. :)
Actually i have two set of details in the form where it should pop up two same answer in the both text field. Can be say as another copy of the details. My D1-D10 is my details in column of excel sheet.
Thanks for ur suggestion on turning D1-D10 into an array, will do it.

My problem here is the details of each row should appear on each of the text field. But whenever I put different model name, it will eventually display the data in row1 of each column only. Why is it not searching through other row of data.

The output I want is, if i select the row6, all the data from row6 should display in the text field.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.