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

I need some help with VB Code....Please help me!!! 2

Status
Not open for further replies.

tcurtis

Programmer
Oct 3, 2001
54
US
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 Output 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


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


 
It might help if you posted exactly what the problem with this code is, e.g. what it isn't doing that you want, what error messages it gives you, whatever.
 
I am not getting any erors....I am trying to populate my database with this .csv file and the database is still empty but the immediate window prints the values...why isn't the csv populateing my database? The database is still empty.
 
it might be because your opening the .csv for output, instead of opening it for input.(Open "C:\project.csv" For Output As #1), should be Open for Input
 
Here, it's written in Access because I had Access open at the time:

The contents of 'MyFile.txt':
Code:
33, John, Smith
25, Mike, Jones
40, Judy, Wilson

The procedure to import:
Code:
Public Sub GetRecords()
Dim db As Database, Age As Byte, FirstName As String, LastName As String
    
    'replace the following if using VB instead of Access VBA
    Set db = CurrentDb
    
    Open "C:\MyText.txt" For Input As #1
    
    While Not EOF(1)
        Input #1, Age, FirstName, LastName
        
        db.Execute "INSERT INTO MyTable VALUES (" & Age & ", '" & FirstName _
                 & "', '" & LastName & "')"
    Wend
    
    Close #1
End Sub

Question: why does your boss care about which method you use to do the importing??? Your macro was probably the most efficient method because Access optimizes it's built-in methods.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top