VB Programming in Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a VB Module that creates an array of numbers and I would like to know
how to dump them into (populate) a table in Access. And also create a new
table from the VB Module, hopefully in the background. Any one who has any
examples of code I would appreciate suggestions.
 
Public Sub ArrayToTable()

'for testing only, delete table if exists
On Error Resume Next
CurrentProject.Connection.Execute "DROP TABLE ArrayTest"
On Error GoTo 0

'create table
CurrentProject.Connection.Execute "CREATE TABLE ArrayTest " & _
"(NumberField int PRIMARY KEY)"

'we don't need the array, we could assign the numbers directly
'to the table, this is for demonstration purposes only
Dim lngLoop As Long
Dim alngNumbers(9) As Long
For lngLoop = 0 To 9
alngNumbers(lngLoop) = lngLoop
Next lngLoop

For lngLoop = LBound(alngNumbers) To UBound(alngNumbers)
CurrentProject.Connection.Execute "INSERT INTO ArrayTest " & _
"(NumberField) VALUES (" & alngNumbers(lngLoop) & ")"
Next lngLoop

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Strange files/modules in VB window 1
Modules Corrupted 2
VB IDE 1
Timeout in VB 5
VBA or VB? 1
Help running VB Code 1
vb problem 1
Usin VB in Sql Server 7

Back
Top