Link to home
Start Free TrialLog in
Avatar of dj__jebus
dj__jebus

asked on

Visual Basic Arrays and Access Database

I have a column in my access database table called "Lines", and I need it to be an array type somehow so that for each record in the table I can have multiple "Lines" and for each "Line" I can store an X1, Y1, X2, Y2.  Also, how would I use a select statement and update statement from visual basic to access and update that field?  I know I could just create a whole new table to do this for me, but would perfer not too.  I don't know a lot about access, use it rarely, so I'm sure is something beyond the basics I know to accomplish this.

Thanks, Jebus
Avatar of dj__jebus
dj__jebus

ASKER

I just found the menu thing insert a subdatasheet.  Is this along the lines if something I could use?  How does it work and how would I implement it in my vb project to make it work?  Or is it completely unrelated?

Thanks Jebus
How about adding them to the field seperated by a carraiage return:

' add a refence to Microsoft ActiveX Data Objects Library:

Dim DataBase As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
DataBase = "C:\MyDataBase"

' open Database Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & DataBase & "'"
cn.CursorLocation = adUseClient
cn.Open

' open recordset
Set rs = New ADODB.Recordset
rs.Open "Select * From MyTable", cn, adOpenKeyset, adLockOptimistic

' add new record to Table
rs.AddNew
rs.Fields("Lines").Value = X1 & vbCr & X2 & vbCr & Y1 & vbCr & Y2
rs.Update

' update current record
rs.Fields("Lines").Value = X1 & vbCr & X2 & vbCr & Y1 & vbCr & Y2
rs.Update

' close recordset
rs.Close
Set rs = Nothing

' close connection
cn.Close
Set cn = Nothing


I would like to try using this subdatasheet thing.  I have a table called "Jobs" in which I have a subdatasheet called "Walls"  In Walls I have my WallID, X1, Y1, X2, Y2 columns.  So all I need now is to write my sql string to be able to select and update things from the Walls table for each record in Jobs.

Thanks Jebus
ASKER CERTIFIED SOLUTION
Avatar of dj__jebus
dj__jebus

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial