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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning Variables to Access Table Record Fields

Status
Not open for further replies.

deepgrewal22

Instructor
May 2, 2005
108
I have designed a form in Access which writes to a table once it has completed validating and checking the input data. I now need to be able to pull a record from the underlying table and parse the fields in the record into variables.

What is the proper syntax to assign variables to substrings of an existing record in an Access database table?

Deep Grewal
"Microsoft Works" - oxymoron
 
Remou,

Thanx for that useful link. I was able to get this far, but how do I access the data that is stored in the Variant (rec)?

Code:
Dim db As Database
Dim cursor As Recordset
Dim rec As Variant
Set db = OpenDatabase("D:\Documents and Settings\aadpsdg\My Documents\My Projects\AutoTime\O.T. Acceleration\AQE - Automated Query Executor\AQE 2.0.0\AQE 2.0.0.mdb")
Set cursor = db.OpenRecordset("SELECT * FROM AQE_Schedule")
rec = cursor.GetRows(1)
[Code]

Deep Grewal
"Microsoft Works" - oxymoron
 
Some notes:

Code:
Dim db As Database
Dim cursor As DAO.Recordset
Dim rec As Variant
Dim intFirstRec As Integer
Dim intLastRec As Integer
Dim intFirstField As Integer
Dim intLastField As Integer
  
Set db = OpenDatabase("D:\Documents and Settings\aadpsdg\My Documents\My Projects\AutoTime\O.T. Acceleration\AQE - Automated Query Executor\AQE 2.0.0\AQE 2.0.0.mdb")
Set cursor = db.OpenRecordset("SELECT * FROM AQE_Schedule")

If Not cursor.EOF Then
    rec = cursor.GetRows(1)
    intFirstRec = LBound(rec, 2)
    intLastRec = UBound(rec, 2)
    intFirstField = LBound(rec, 1)
    intLastField = UBound(rec, 1)

    For i = intFirstRec To intLastRec
        For j = intFirstField To intLastField
        
            Debug.Print rec(j, i)
        Next
    Next
End If
 
Remou,

Thanx for the code. It works well I replaced the following line:

Code:
Debug.Print rec(j, i)

With this one instead because I didn't see any output being printed on screen.

Code:
MsgBox (rec(j, i))


Deep Grewal
"Microsoft Works" - oxymoron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top