a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 94|回复: 0

[Access] 如何设置组合框或列表框的行来源为函数

[复制链接]
发表于 2012-7-31 22:26:35 | 显示全部楼层 |阅读模式
如何设置组合框或列表框的行来源为函数
) D- U" H' m8 \4 a) r 下列代码是一个例程,将行来源设置为这个函数: . L" H/ z2 a' I1 L4 r4 g( R% t8 E
  Public Function valueList(ctl As Control, _
" n/ v" d# m3 o8 Z  varID As Variant, _
3 Q5 D# F; u$ F+ B6 L4 `$ [" u0 ^  lngRow As Long, _. o" ~; ?( [) k5 r% Q
  lngCol As Long, _
* ~1 W5 e1 ^, b7 u" Z5 }1 N' i* P  intCode As Integer) As Variant3 G$ {7 {; K" s3 f6 n% O
  Dim varRetVal As Variant
+ T1 o; D; C) l7 C' O( _  Dim strField As String
! O  u8 t+ M0 a# D  Dim strField As String
7 u" u& b; c, v3 c+ u) ~  Dim strSQL As String" l* a- q6 o  g3 x+ d
  Dim strList As String% l$ ^) R* p1 [: E2 [
  Dim intLoopRow As Integer
. l+ U( U  x: L& G( x9 X7 u7 l  Dim intLoopCol As Integer
" o. V8 R9 {' I  Dim cnn As ADODB.Connection' j! ?; Y) \! x
  Dim RST As ADODB.Recordset
8 ?/ t$ ~1 N. p5 u  Static svarArray() As Variant
% ?; z# y# P* z* a/ C6 M; ~  Static sintRows As Integer
7 a: R+ O: ]& x9 s  Static sintCols As Integer
! D! M: z+ W- o& Q0 n, V  On Error GoTo Proc_err3 @6 w+ ^! ?, S& @: T( H" |7 ?2 \
  Select Case intCode2 ^  |+ w0 R* B" v% z; s8 f3 |# p  F
  Case acLBInitialize
& l9 ?9 M6 L7 O" G  On Error Resume Next
  N/ |/ f) Y9 L4 [9 P( C! \0 W# i  intLoopRow = Ubound(svarArray), A" A* V  J' u: w: _' ]
  If Err  0 Then
" x4 G9 C& C! c7 [& ~  On Error GoTo Proc_err8 j9 S. |, L) Z1 w( S
  'populate the customer recordset) Z% o7 d9 E& Q9 n
  Set cnn = New ADODB.Connection
0 R* z' }7 N- m; H1 j  cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
9 _4 X: V) P3 e; Y3 ?  c1 W, i7 P) D  cnn.Properties("Data Source") = CurrentProject.Path & "\data share\data.dat". v+ K/ M& _2 [0 J4 N
  cnn.Properties("Jet OLEDB:Database Password") = "123456789222"/ N# j- p' u# p6 c1 A
  cnn.Open2 S) p* S9 k" u+ z7 E) i
  ' With cnn
4 o! n% h/ T* v  '.Provider = "Microsoft.Jet.OLEDB.4.0"
, R! O, w* G5 ^  'this gets stored values from the only' d# l& C5 d4 m* m
  'local table to allow flexibility% v: p) k9 g* q- ]- w
  '.ConnectionString = CurrentProject.Path & "\data.dat" 'should be changed: L0 g1 W" H5 {& G3 [0 @$ T1 }
  '.Properties("Jet OLEDB:Database Password") = "123456789222"6 ]1 t# G4 U& n3 H
  '.Open; N$ O. A7 W+ N+ a# a9 ~
  'End With
5 ^& d6 W" e! E: `/ F  Set RST = New ADODB.Recordset, S+ ^& O- c' {" g
  With RST! J& V$ R# d+ M- I+ |# `& H
  .ActiveConnection = cnn
, [4 ?6 v) B& ?, f  .Source = "select usysuser.userid,usysuser.username from usysuser" 'should be changed3 ~& D& R3 N6 Q
  .CursorLocation = adUseClient% c3 a0 g. X8 m
  .CursorType = adOpenDynamic; o# G' t6 e  ]+ K, C' L( a
  .LockType = adLockReadOnly' {2 p1 E# f" a4 j2 T' @- w$ |1 @
  .Open , , , , adCmdText0 m" k. f) v/ H" R% B$ t
  .MoveLast# ?! j5 t' @) g6 Y4 E1 [
  sintRows = .RecordCount
* r* I9 F( L( N- e2 d/ T2 c+ N  .MoveFirst" y8 m" e, _% B
  sintCols = .Fields.Count
) L' i! r9 ^$ F. L( T3 n) ~# A  End With 'rst
) E# g5 K/ F- ~$ |6 L  Set cnn = Nothing
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-4-29 14:57 , Processed in 0.299118 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表