hello can you help me where to put the messagebox "file not found"...because if i put on else after the grd.Rows = grd.Rows + 1
only one data having this precint number will be display all i want that all of them will be display..sample ..D-314 is the precint number
having this precint number will be display ..hoping for your positive responds thanks in advance..

///notepad

"D-314","London","0001","cyndy","miller","s","ffff",26
"C-245","America","0002","deca","michael","s","fff",29
"D-314","Thailand","0003","ffffff","hhhhh","s","kkkkkkk",21
"C-245","New Zealand","0004","ssssss","fljjjjje","s","jjjjj",22
"D-314","Hungary","0005","jerusalem","emmanuel","s","kkkkk",25
"D-314","Afganistan","0006","ppppp","ttttttt","d","nnnnns",29
"C-245","California","0007","lllllll","rrrrrrrr","s","upon",30
"E-344","Korea","0008","pppp","l;k;lk;l","d","dk;k;k",29
"D-314","Norway","0009","jlkjlkjl","qlkjlkjlk","s","lkjlkj",26
"C-245","South Korea","0010","ffff","ff","f","ff",34
"C-245","North Korea","0011","fdfdfdf","fff","s","f",67
"A-342","North America","0012","fff","f","f","f",23
"D-314","AFrica","0013","neeeee","jer","k","mexico",22


Public Sub header()

grd.Clear
grd.Rows = 2
grd.Cols = 4

grd.ColWidth(1) = 2000
grd.ColWidth(2) = 1500


With grd

.TextMatrix(0, 0) = "Voters idno"
.TextMatrix(0, 1) = "Voters name"
.TextMatrix(0, 2) = "address"
.TextMatrix(0, 3) = "age"

End With

End Sub

Private Sub Form_Load()
header
End Sub

Private Sub txtpno_KeyDown(KeyCode As Integer, Shift As Integer)
gFnum = FreeFile

If KeyCode = 13 Then

m_pno = Trim(UCase(txtpno.Text))
txtpno.SetFocus

Open "voters.dat" For Input As #gFnum


Do Until EOF(gFnum)

Input #gFnum, pn, adress, vidno, last, first, middle, address, age

If m_pno = pn Then

With grd

.TextMatrix(grd.Rows - 1, 0) = vidno
.TextMatrix(grd.Rows - 1, 1) = last + "," + first + "" + middle
.TextMatrix(grd.Rows - 1, 2) = address
.TextMatrix(grd.Rows - 1, 3) = age
End With
grd.Rows = grd.Rows + 1
End If

Loop


Close #gFnum

End If


End Sub

Hi
I dont know wether this is right or not but you can use else to put the msg box

If m_pno = pn Then

With grd

.TextMatrix(grd.Rows - 1, 0) = vidno
.TextMatrix(grd.Rows - 1, 1) = last + "," + first + "" + middle
.TextMatrix(grd.Rows - 1, 2) = address
.TextMatrix(grd.Rows - 1, 3) = age
End With
grd.Rows = grd.Rows + 1
else
 MsgBox "No Records Found in DataGrid!"
    grd.Clear
End If

please I am not sure.....but this may prove to be helpful

What only unharmful after effect it(this code) will have is this grid will have a blank row after the last record.

If m_pno = pn Then

With grd

.TextMatrix(grd.Rows - 1, 0) = vidno
.TextMatrix(grd.Rows - 1, 1) = last + "," + first + "" + middle
.TextMatrix(grd.Rows - 1, 2) = address
.TextMatrix(grd.Rows - 1, 3) = age
.Rows = grd.Rows + 1

End With

End If

And for record not found message use this at the end of procedure i.e. before "End Sub"

if grd.Rows = 2 then
MsgBox "No Records Found in DataGrid !"
end if

As if any matching record has found "grd.rows" value will be greater than 2.

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.