943,549 Members | Top Members by Rank

Ad:
Oct 6th, 2008
0

VBA Inserting data to table

Expand Post »
Heya

I have to write a script within MS Access 2003 using Visual Basic for Applications to read in data from a textfile and insert it into the table. I began my programming path using dot.Net C# and started database manipulation using Sql Server. So this is kind of like a step backwards for me ... Im so used to seeing the intellisense pop up all the time to help me out.

I have previously set up a database (Insert, Update, Delete etc) using stored procedures and called them in the code accordingly. However, MS Access doesnt have stored procedures .. so I have been trying to use an ADODB.Command to insert data to the table.

I am reading data in from a specific file directory, once one file is finished reading to the end the next one is read etc... Im am pulling out the values and passing them into an array... so I want to be able to insert each individual element of the array into the database table now

Here is the code I have so far
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Private Sub InsertAnswers(ByVal strSpecialist As String) 'For testing the rest have been removed
  3. 'Insert a new row
  4. On Error GoTo ErrorHandler
  5. 'Connection Variable
  6. Dim strSQL As String
  7. Dim insert_conn As ADODB.Connection
  8. Set insert_conn = New ADODB.Connection
  9. insert_conn.Provider = "Microsoft.Jet.OLEDB.4.0"
  10. insert_conn.Open "C:\Users\User\Documents\Current Projects\myDatabase.mdb"
  11.  
  12. 'Command Variables
  13. Dim insert_Command As ADODB.Command
  14. Set insert_Command = New ADODB.Command
  15. inset_Command = "INSERT INTO FactFind(Specialist) VALUES(@specialist)"
  16.  
  17. 'Declare and Initialise Parameters
  18. Dim specialist_Param As ADODB.Parameter
  19. Set specialist_Param = New ADODB.Parameter
  20.  
  21. specialist_Param.Value = strSpecialist
  22.  
  23. insert_Command.Parameters.Add (specialist_Param)
  24. End Sub

I dont mean for anyone to GIVE me the answers ... but a little advice or guidance would be great.

Thanks so much

Elmo
Reputation Points: 30
Solved Threads: 0
Junior Poster in Training
Elmo_loves_you is offline Offline
85 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Openning Folders with VB
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Excel VBA ODBC retrieving results





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC