Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 newbie datagrid on second form

Status
Not open for further replies.

srussell705

Programmer
Mar 26, 2001
13
US
I have been asked to add a second form to an existing simple exe. That form will be loaded from backend rs that I make.

Should I pass the rs to the form, or should the form load receive a param to do it's own query instead?

How do I force the new form to show if there is data returned to the rs?

Think of adding a visual proof to data entry person that there are outstanding invoices for this customer.

Last what is best way to load data into datagrid in vb6? I do C# or dba for SQL server normaly.

TIA

__Stephen
 
This code was written by others lost in antiquity
Tick project/references to Microsoft ActiveX Data Objects 2.5 Library
Insert a datagrid and edit it with the columns the names of your fields you want

Make a [criteria] statement to get the records you want.
Eg "Select * from MyTable order by [ID]"

'declarations at top of form code
Public CN As New ADODB.Connection ' Conection tool
Public RS As New ADODB.Recordset ' Recordset tool
dim Criteria as string

Sub ShowData
' Open database conection
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\MyFolder\MyDatabase.mdb"
' The following instruction must be executed before opening our recordset
RS.CursorLocation = adUseClient
' Opening the recordset
RS.Open Criteria, CN, adOpenStatic, adLockOptimistic
' Now we set our DataGrid to have the content of the db
Set DataGrid1.DataSource = RS
Set DataGrid2.DataSource = RS

end sub

sub FinishedEditing
RS.Update
RS.Close
CN.Close
end sub



You can have as many datagrids as you like

You can also use the data control but I often have trouble saving data with this.
 

You may do this in your Form1:
Code:
Private Sub cmdShowForm2_Click()

With Form2
    [green]'Fill your Grid on Form2 here[/green]
    .grdMyGrid.AddItem "Stuff here"
    ....
    .Show
End With

Me.Hide

End Sub

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top