i have 2 forms..
the first one is for displaying students record while the other one is for searching student record (in datagrid)
i want to display the searched record of a student from form2 to textboxes in form1..how is this possible?

If DataGrid1.Col = 0 Then
    If Text1.Text = "" Then
        MsgBox "Enter Student ID"
            refer = DataGrid1.Col
            refer = Text1.Text
            bol = True
    End If

    MsgBox "Click StudentID"
End If

End If

You need top qualify the teddtbox anme with the containing form name and then assign any value that you wantto display.


form1.textbox1.text = "Hello"

Where will Text1 get its data from? If it is from the grid, I assume you used code like -

Text1.Text = DataGrid.Col(0) ''and so forth for all other fields...

refer = DataGrid1.Col refer = Text1.Text

You gave refer 2 values here... a bit confusing.

Also use conventional naming methods, good for cutting out possible future errors, i.e. formal should be frmFormal, refer should be strRefer etc. :)

Your code to show the data in your formal form then...

formal.Text1.Text = refer


your formal form will now show with the data as selected from grid.

this is my new code:

If DataGrid1.Col(0) Then

    refer = DataGrid1.Col(0)
    Rs.Open "select *from studtable where StudID = '" & refer & "'", Cn, 3, 2
    formal.txtstud.Text = refer
    MsgBox "Click StudentID"
End If

i got an error:
Compile Error
Wrong number of arguments or invalid property assignment

.Col(0) is being highlighted...

Thats because you are making a call to the datagrid coloumn without it having the focus. set the focus to coloumn first...

the if statement does not make a lot of sense it probably should be something like

if not isnull(datagrid1.col(0)) then


if datagride1.col(0) <> 0 then
Be a part of the DaniWeb community

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