例如:
我要以dbcombo或textbox的text的值作為搜尋條件,在 Test.mdb裡的"員工資料"這個資料表裡,篩選出"部門別"這個欄位符合搜尋條件的每一筆資料然後透過textbox或MSFlexGrid顯示出來我應該怎麼做呢??
簡單的說當DBCombo下拉式選單選定部門別時(Area=2),Textbox或MSFlexGrid會依照選擇的部門別,顯示出屬於該部門別的員工資料而不顯示其他部門的員工資料...................麻煩大大賜教了!!
data控制項的Recordset有這個功能嗎??
2006-10-25 00:03:02 · 1 個解答 · 發問者 Joseph Chung 1 in 電腦與網際網路 ➔ 軟體
WJS 大大....那如何將結果顯示在Textbox或MSFlexGrid中呢??
2006-10-25 19:41:23 · update #1
WJS老哥謝謝我自己試著把結果顯示在MSFlexGrid中結果成功了....但是我希望把結果一筆一筆多行顯示在Textbox裡該怎樣做呢??
2006-10-25 20:22:39 · update #2
'要多行顯示在TextBox時,將TextBox的MultiLine設成True,ScrollBars=3-兩者皆有;DataSouse=""(不要跟Data物件連結)'因你沒說明要顯示何欄位,我只好把員工資料裡面所有欄位都顯示出來,所以TextBox拉大一點Private Sub Command1_Click() Dim S$, F$, K$, Re As Recordset, I%, T% S = "Select * From 員工資料 Where [Area]=" & DBCombo 'Area是數值欄時 '或 'S = "Select * From 員工資料 Where [Area]='" & DBCombo &"'" 'Area是文字欄時 F = FontName: FontName = "細明體": Text1.FontName = "細明體" Set Data1.Recordset = Data1.Database.OpenRecordset(S) Data1.Refresh Set Re = Data1.Recordset If Re.RecordCount > 0 Then T = Re.Fields.Count - 1 ReDim W(T) As Integer '記錄欄名長度到W(I) For I = 0 To T W(I) = Len(Re.Fields(I).Name) + 1 Next '找出每個欄位最長資料長度記錄到W(I) Re.MoveFirst Do Until Re.EOF For I = 0 To T If W(I) < Len(Re.Fields(I)) + 1 Then W(I) = Len(Re.Fields(I)) + 1 Next Re.MoveNext Loop '將欄名和資料以各最大長度放入S S = "" For I = 0 To T K = Re.Fields(I).Name S = S & K & String(W(I) - Len(K), " ") Next S = S & vbCrLf Re.MoveFirst Do Until Re.EOF For I = 0 To T If IsNull(Re.Fields(I)) Then K = "" Else K = Re.Fields(I) End If S = S & K & String(W(I) - Len(K), " ") Next S = S & vbCrLf Re.MoveNext Loop 'S代入Text1 Text1 = Left(S, Len(S) - 1) End If '還原表單字型 FontName = F Set Re = NothingEnd Sub
2006-10-25 07:34:26 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋