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

Isn't there anyone who can help me with VB Code?? I am desparate...

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 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


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


 
Try this:

Option Compare Database
Private sFileName As String

Private Sub cmdOK_Click()

Dim rs As Object
Dim rstSports As Recordset
Dim iCounter As Integer
Dim sLine As String
Dim vArray() As String

If Len(sFileName) = 0 Then
MsgBox "Enter a valid text file name"
Else

Set rs = CurrentDb.OpenRecordset("Sports")

Open sFileName For Input As 1
Do While Not EOF(1)
Line Input #1, sLine
vArray = Split(sLine, ",")
rs.AddNew
For i = 0 To UBound(vArray)
rs(i) = vArray(i)
Next
rs.Update
iCounter = iCounter + 1
Loop
Close #1
MsgBox "Total number of records added " & iCounter

rs.Close
Set rs = Nothing

End If

End Sub

Private Sub txtFileName_LostFocus()
sFileName = txtFileName.Text
End Sub

FILE DATA:
Chipper, Jones, Baseball
Lawrence, Taylor, Football
Micheal, Jordan, Basketball
Tiger, Woods, Golf
Venus, Williams, Tennis

 
That might help me if you put the names of my files in place of yours....hehehe.....my database name is Projectcsv.mdb and my files name is project.csv is there any more help you can give me?
 
I assuming that the projects.csv file is delimited by commas, so my code would something like this.

I gave you two ways of doing the adding records to the table.

Option Compare Database
Private sFileName As String
'Enumerated values to use with the AddRecord procedure
'if used

Enum BDS_Fields
BDS = 0
Filler = 1
LoggedDate = 3
DesignDescription = 4
Status = 5
Developer = 6
BusinessAnalyst = 7
Packet = 8
DesignType = 9
System = 10
ExpectedDate = 11
Department = 12
End Enum

Sub Open_Records()

Dim rs As Object
Dim rstSports As Recordset
Dim iCounter As Integer
Dim sLine As String
Dim vArray() As String

Set rs = CurrentDb.OpenRecordset("BDS")

Open sFileName For Input As 1
Do While Not EOF(1)

'Each line item contains the following fields:
' BDS, Filler, LoggedDate, strDesignDescription,
' strStatus, strDeveloper, strBusinessAnalyst,
' Packet, strDesignType, strSystem, ExpectedDate,
' strDepartment

Line Input #1, sLine

'Use the Split string function to find all the
'the delimited items in a string
vArray() = Split(sLine, ",")

'* START DELETE HERE IF USING THE ADDRECORD SUB
'Add a new record to the BDS table
rs.AddNew

'Loop through each field in the recordset
'Assumption: The line items in the projects.csv table
'are in the same position as the BDS table

For i = 0 To UBound(vArray)
rs.Fields(i).Value = vArray(i)
Next
'*END DELETE HERE

' OR you could delete the code above and call the
' AddRecord procedure to accomplish the same task

' AddRecord rs, vArray()

'Update the BDS table
rs.Update

iCounter = iCounter + 1
Loop

Close #1

rs.Close
Set rs = Nothing

End If

End Sub

Sub AddRecord(rs as Recordset, vArray() as String)
With rs
.AddNew
!BDS = vArray(BDS)
!Filler = vArray(Filler)
!LoggedDate = vArray(LoggedDate)
!DesignDescription = vArray(DesignDescription)
!Status = vArray(Status)
!Developer = vArray(Developer)
!BusinessAnalyst = vArray(BusinessAnalyst)
!Packet = vArray(Packet)
!DesignType = vArray(DesignType)
!System = vArray(System)
!ExpectedDate = vArray(ExpectedDate)
!Department = vArray(Department)
.Update
.Bookmark = .LastModified
End With

End Sub
 
NEEDED TO MAKE A SMALL ALTERATION:

I assuming that the projects.csv file is delimited by commas, so my code would something like this.

I gave you two ways of doing the adding records to the table.

Option Compare Database
Private sFileName As String
'Enumerated values to use with the AddRecord procedure
'if used

Enum BDS_Fields
BDS = 0
Filler = 1
LoggedDate = 3
DesignDescription = 4
Status = 5
Developer = 6
BusinessAnalyst = 7
Packet = 8
DesignType = 9
System = 10
ExpectedDate = 11
Department = 12
End Enum

Sub Open_Records()

Dim rs As Object
Dim rstSports As Recordset
Dim iCounter As Integer
Dim sLine As String
Dim vArray() As String

Set rs = CurrentDb.OpenRecordset("BDS")

Open sFileName For Input As 1
Do While Not EOF(1)

'Each line item contains the following fields:
' BDS, Filler, LoggedDate, strDesignDescription,
' strStatus, strDeveloper, strBusinessAnalyst,
' Packet, strDesignType, strSystem, ExpectedDate,
' strDepartment

Line Input #1, sLine

'Use the Split string function to find all the
'the delimited items in a string
vArray() = Split(sLine, ",")

'* START DELETE HERE IF USING THE ADDRECORD SUB
'Add a new record to the BDS table
rs.AddNew

'Loop through each field in the recordset
'Assumption: The line items in the projects.csv table
'are in the same position as the BDS table

For i = 0 To UBound(vArray)
rs.Fields(i).Value = vArray(i)
Next

'Update the BDS table
rs.Update
'*END DELETE HERE

' OR you could delete the code above and call the
' AddRecord procedure to accomplish the same task

' AddRecord rs, vArray()

iCounter = iCounter + 1
Loop

Close #1

rs.Close
Set rs = Nothing

End If

End Sub

Sub AddRecord(rs as Recordset, vArray() as String)
With rs
.AddNew
!BDS = vArray(BDS)
!Filler = vArray(Filler)
!LoggedDate = vArray(LoggedDate)
!DesignDescription = vArray(DesignDescription)
!Status = vArray(Status)
!Developer = vArray(Developer)
!BusinessAnalyst = vArray(BusinessAnalyst)
!Packet = vArray(Packet)
!DesignType = vArray(DesignType)
!System = vArray(System)
!ExpectedDate = vArray(ExpectedDate)
!Department = vArray(Department)
.Update
.Bookmark = .LastModified
End With

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top