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!

Prob. to display relevant record on datagrid when select datacombo.

Status
Not open for further replies.

awinnn

MIS
Jul 21, 2003
166
MY
Hi,
I have Datacombo(cbofields(0)) and Datagrid (grdDataGrid) on the form. What i'm trying to do is when i select item on the datacombo, only the relevant record will be displayed on the datagrid. By default, the datagrid will display all the records.
This code is taken from the sample database on the internet.
This is what i've done,

Code:
Private Sub cbofields_Click(Index As Integer, Area As 
                            Integer)
    If Area = 2 Then
         selmodel = cbofields(0).BoundText
         Form_Load
    End If
End Sub

Private Sub Form_Load()
  Dim db As Connection
  Me.Top = 0
  Me.Left = 0
  Me.Height = 5130
  Me.Width = 6090
  Set db = New Connection
  db.CursorLocation = adUseClient
  
  db.Open "PROVIDER=MSDataShape;......."
 
  Set adoPrimaryRS = New Recordset
  Set rsgtotal = New Recordset

  If selmodel = "" Then
       adoPrimaryRS.Open "SELECT cust_no, type, pt, 
         receivedt FROM [orderdetails] LEFT JOIN [orders] 
         ON [orderdetails].sn = [orders].sn", db, 
         adOpenStatic, adLockOptimistic
  Else
       adoPrimaryRS.Open "SELECT [customer].cust_no, 
         [orderdetails].type, [orderdetails].pt, 
         [orders].receivedt FROM ([orders] LEFT JOIN 
         [customer]ON [orders].cust_no = 
         [customer].cust_no) INNER JOIN [orderdetails] ON 
         [orders].sn= [orderdetails].sn WHERE type = " 
         & "'" & Trim(selmodel) & "'" & ", db"
  End If
 
  AdoType.ConnectionString = "PROVIDER=MSDataShape;......."

  AdoType.RecordSource = "SELECT type FROM [model]"
  Set cbofields(0).RowSource = AdoType
  Set grdDataGrid.DataSource = adoPrimaryRS

  mbDataChanged = False
End Sub

When i open the form, by default the datagrid will display all the records, but the problem is, when i select on the datacombo, the datagrid didn't display the relevant record.
The problem is, it displays all the records.

Any idea? thanx in advance..;)
 
Hi

I am also doing the samething but in this manner and it works absolutely fine for me.

The following Code is on Combo Click event:

Dim rSql As String
Dim rRs As ADODB.Recordset

rSql = "Select fFloorNo, fRoomNo, fRoomOwner, bBuildingCode from RoomsMaster" _
& " where bBuildingCode ='" & Right(cmbBuilding.Text, 5) & "'"

Set rRs = New ADODB.Recordset
rRs.Open rSql, cn, adOpenKeyset, adLockOptimistic, adCmdText

If Not rRs.EOF Then rRs.MoveLast

Set dgRooms.DataSource = rRs
dgRooms.Col = 0
dgRooms.SetFocus


HTH

Gazal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top