relate 2 datacombo

dpapala
04-17-2004, 03:22 AM
hi it's me again i have another problem. i have in a form 2 datacombo's. The first one take values with an sql query from my access db, no problem. The second which is in the same form i want to take values again from an sql query but in the sql i want to use the value that i select from the first datacombo.
Any suggestions

Shurik12
04-17-2004, 06:00 AM
Your sql should look similar too:
(assuming Field1 is Text)

"Select * From Table1 Where Field1= '" & DBCombo1.Text & "'"


Shurik.

dpapala
04-19-2004, 02:46 AM
hi again,
i've tried that but it doesn't working. the seecond combo does not show anything.

Shurik12
04-19-2004, 03:10 AM
Please show how you are trying to do it.
Please use vb-tags for a better readability.

dpapala
04-19-2004, 03:53 AM
Private Sub Form_Activate()
Text1.SetFocus
Dim mConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim rsts As New ADODB.Recordset
Dim mConnm As New ADODB.Connection
Dim dstr As String
Dim strConn As String
Dim StrSQl As String
strConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\dimitris\My Documents\odeio\data1.mdb"
StrSQl = "SELECT distinct name FROM schools"

mConn.Open strConn

rst.CursorLocation = adUseClient
rst.Open StrSQl, mConn
Set DataCombo1.RowSource = rst
DataCombo1.ListField = rst(0).Name 'OrderID
StrSQl = "SELECT depart FROM schools where name= '" & DataCombo1.Text & "'"

mConnm.Open strConn

rsts.CursorLocation = adUseClient
rsts.Open StrSQl, mConnm
Set DataCombo2.RowSource = rsts
DataCombo2.ListField = rsts(0).Name 'OrderID

End Sub

TheDutch IceMan
04-19-2004, 04:31 AM
use standard combo's and fill them with your data like this:


'controleer of de verbinding nog open is
Call checkConnectionState(gobjConn)

Dim objRsPWCW As ADODB.Recordset
Set objRsPWCW = New ADODB.Recordset

With objRsPWCW
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.ActiveConnection = gobjConn
.Source = "SELECT ID_plaats, plaats FROM tblPCWP ORDER BY plaats"
.Open
End With
Do Until objRsPWCW.EOF
Me.lstGeboorteplaats.AddItem objRsPWCW!plaats
lstGeboorteplaats.ItemData(lstGeboorteplaats.NewIndex) = objRsPWCW!ID_plaats
objRsPWCW.MoveNext
Loop
objRsPWCW.Close
Set objRsPWCW = Nothing
blnGebPlaatsFlag = True



Now, when you clicked the lstGeboorteplaats, you have to retrieve the ID and fill the second combo on the same way but the variabele in your SQL QUERY can be retrieved as follows:



Private Sub lstGeboorteplaats_LostFocus()
Dim msg
msg = lstGeboorteplaats.ItemData(lstGeboorteplaats.ListIndex) & " "
msg = msg & lstGeboorteplaats.Text
MsgBox msg
End Sub


Try it, then you know what you're doing instead of using those standard datacombo's and other standards stuff in VB ;)


Your query could look like this

"SELECT * FROM tblYourTable WHERE ID = " & lstGeboorteplaats.ItemData(lstGeboorteplaats.ListIndex)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum