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

I still can't populate the database with a .CSV file...HELP!!!

Status
Not open for further replies.

tcurtis

Programmer
Oct 3, 2001
54
US
I cannot figure out how to populate my database with a .csv file! This is for my externship and I am desparate...help!! The name of my database is Projectcsv.mdb and the name of my .csv file is project.csv! I need good old VB code that will open read and write this .csv file to my newly created databse.

Here is the code I have and thanks to any help I get!
Option Compare Database
Option Explicit

Dim dbsPractice1 As Database
Dim rstproject As Recordset
Dim wrkJet As Workspace
Dim BDS As Integer
Dim Filler As Long
Dim LoggedDate As Integer
Dim strDesignDescription As String
Dim strStatus As String
Dim strDeveloper As String
Dim strBusinessAnalyst As String
Dim Packet As Integer
Dim strDesignType As String
Dim strSystem As String
Dim ExpectedDate As Integer
Dim strDepartment As String

Sub Open_Records()
'create microsoft jet workspace object.
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
'Opens Database
Set dbsPractice1 = wrkJet.OpenDatabase("C:\Practice1.mdb", True)
'Opens the project file to input it into the database
Open "C:\project.csv" For Input As #1
Do While Not EOF(1)
Input #1, BDS, Filler, LoggedDate, strDesignDescription, strStatus, strDeveloper, strBusinessAnalyst, Packet, _
strDesignType, strSystem, ExpectedDate, strDepartment
Debug.Print "Opening table-type recordset " & _
"where the source is a QueryDef object..."
Set rstproject = dbsPractice1.OpenRecordset( _
"BDS", dbOpenTable)

AddRecord rstproject, BDS, Filler, LoggedDate, strDesignDescription, strStatus, strDeveloper, strBusinessAnalyst, Packet, strDesignType, strSystem, _ ExpectedDate, strDepartment
Write #1, rstproject, BDS, Filler, LoggedDate, strDesignDescription, strStatus, strDeveloper, strBusinessAnalyst, Packet, _
strDesignType, strSystem, ExpectedDate, strDepartment

Loop
Close #1
End Sub

Function AddRecord(rstproject As Recordset, BDS, Filler, LoggedDate, strDesignDescription, strStatus, strDeveloper, strBusinessAnalyst, Packet, _
strDesignType, strSystem, ExpectedDate, strDepartment)

' Adds a new record to a Recordset using the data passed
' by the calling procedure. The new record is then made
' the current record.
With rstproject
.AddNew
!BDS = BDS
!Filler = Filler
!LoggedDate = LoggedDate
!DesignDescription = strDesignDescription
!Status = strStatus
!Developer = strDeveloper
!BusinessAnalyst = strBusinessAnalyst
!Packet = Packet
!DesignType = strDesignType
!System = strSystem
!ExpectedDate = ExpectedDate
!Department = strDepartment
.Update
.MoveNext
.Bookmark = .LastModified
End With

End Function


Can someone tell me what I am missing here???
Thanks again,
Tammy, Indiana
 
I did it that way and did by means of a macro.....the boss said no....he wants the Open,Read,Addnew methods used... :(
I just can't get it...
 
Are you using access 2000?

did you put a debug.print in your function so you know you are getting into the function? The way I call a function is

call functionname(fl1, etc, etc, etc)

this should match your function signature.
 
This is a way to see my codeing. I have done it three different ways and it wasn't good enough he said ..."Open a record, Read a record, Add a record by means of code...I am so stuck here...he has got me so frustrated that I can't even think anymore....I am doing my externship....and this is part of it so it is kinda a test....anyone help me? I did do the debug.print and the values are there but not in the table of my Database...
 
so you did a debug.print for example inside the function

debug.print "my data = "; rstproject!BusinessAnalyst

and in your immediate window it shows everytime it goes into the function, which should be once for each record in your read write loop??
 
yes....my code is in the top of this message. It prints the values of each field in the immediate window but still an empty db....?????I am so confused....lol
 
Form the code you have in the top window, how can you prove that you are performing the Function???
 
Use some strategicaly placed message box commands to find out what your code is doing. Terry M. Hoey
 
Thaqnk you all....I have finally figured it out!!! Thank you all who have helped me!!!

Tammy
Indiana
 
Um, care to let me in on what you were doing wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top