VBA Inserting data to table

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 83
Reputation: Elmo_loves_you is an unknown quantity at this point 
Solved Threads: 0
Elmo_loves_you's Avatar
Elmo_loves_you Elmo_loves_you is offline Offline
Junior Poster in Training

VBA Inserting data to table

 
0
  #1
Oct 6th, 2008
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
Michelle (Junior Developer)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC