Skip navigation

Sub main()
Dim rndRec
Dim rndFld
Dim CntRec
Dim CntFld
Dim arRec()
Dim arFld()
Dim x, y
rndRec = (Rnd \ 1) + 2
rndFld = (Rnd \ 1) + 2
ReDim arRec(rndRec)
ReDim arFld(rndFld)
 
Dim rs ‘ as new adodb.recordset
Dim Conn ‘ as new adodb.connection
Set Conn = CurrentProject.Connection
 
sql = “Select * From table1;”
rs.Open sql, Conn, 1, 1
rs.MoveLast
CntFld = rs.Fields.COUNT – 1
CntRec = rs.RecordCount – 1
 
For x = 1 To rndRec
arRec(x – 1) = CntRec * Rnd \ 1
        For y = 0 To x
        If arRec(x – 1) = arRec(y) Then arRec(x – 1) = CntRec * Rnd \ 1
        Next
Next
 
For x = 1 To rndFld
arFld(x – 1) = CntFld * Rnd \ 1
        For y = 0 To x
        If arFld(x – 1) = arFld(y) Then arFld(x – 1) = CntFld * Rnd \ 1
        Next
Next
 
Dim strAns
strAns = “”
For x = 0 To rndRec – 1
rs.MoveFirst
        Do While Not rs.EOF
        If rs.AbsolutePosition = arRec(x) Then
        strAns = strAns & “Record No : ” & rs.AbsolutePosition & vbCrLf
        For y = 0 To rndFld – 1
        strAns = strAns & ”     Field No : ” & arFld(y) & ”   Field Name : ” & rs(arFld(y)).NAME & _
        ”   Field Value : ” & rs(arFld(y)) & vbCrLf
        Next
        End If
        rs.MoveNext
        Loop
Next
rs.CLOSE
 
Debug.Print strAns
 
End Sub
 
 
……………………………..
ตอบคำถาม ไว้ที่ http://www.thaicreate.com/index.php?modules=forum/?langkey=2
กระทู้หมายเลข :16733   นามสมมติ : GTM

 

 

 

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

%d bloggers like this: