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"
        Text1.SetFocus
    Else
            refer = DataGrid1.Col
            refer = Text1.Text
            bol = True
            formal.Show
    End If

Else
    MsgBox "Click StudentID"
End If

tudentID"
End If

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

ex.

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

formal.Show 

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
    formal.Show
Else
    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

or

if datagride1.col(0) <> 0 then
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.