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!

How come it worked yesterday but not today....HELP!!! 1

Status
Not open for further replies.

tcurtis

Programmer
Oct 3, 2001
54
US
I am trying to populate the current database with this code I have...I get the error that the database is already open. It is open in code form not table form....I need to populate it with the records of my .csv file. It worked yesterday but not today....why?
Here is my code:

Option Compare Database
Option Explicit

Dim dbsProjectcsv 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 dbsProjectcsv = wrkJet.OpenDatabase("C:\Projectcsv.mdb", True)
Set rstproject = dbsProjectcsv.OpenRecordset("BDS", dbOpenTable)
'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..."


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
.Bookmark = .LastModified
Debug.Print "Opening table-type recordset " & _
"where the source is a QueryDef object..."
End With

End Function
 
Does anyone else use this database? I would close Access (make sure you save if you have made any changes) and then look in the directory that the database is in for a .LDB file. If it exists, someone is in the database, or was and didn't get out properly. This file (should be named the same as your database, but with .LDB as the extension) can be opened with notepad and there is some info as to who is in the DB. If the .LDB file exists and NO ONE is in the DB, it can be deleted.

Take a look and see what you find. Terry M. Hoey
 
There isn't an .ldb file. Can you do this code within the database your currently working in? I have the database open and working within the module section of this database. Do I still have to use the line
Set dbsProjectcsv = wrkJet.OpenDatabase("C:\Projectcsv.mdb", True)? If I don't I can't use this line
Set rstproject = dbsProjectcsv.OpenRecordset("BDS", dbOpenTable)
but then how do I open the table in the current database?

Thanks so much for the help
Tammy, Indiana
 
Thank you very much for your help...I have it working now!
All I did was take out the word TRUE in this line of code:

Set dbsProjectcsv = wrkJet.OpenDatabase("C:\Projectcsv.mdb", True)

You have helped me before so I still vote for you...A big thumbs up!!

Tammy, Indiana
 
As a matter of interest why are you doing this in VBA rather than using Access Import? mike.stephens@bnpparibas.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top