Hi
I'm still learning VB, and I have some code that's giving me a headache.
table name: yeeken
Fields:
1. ProductNumber (primary field)
2. Notes (Memo field)
Each ProductNumber has a corresponding ProductNumber.txt file, which I wish to import into the [Notes] field, thus for example if the product number is ProdX, I would import the file ProdX.txt into the [Notes] field.
All the relevant .txt files are stored in one directory
========
' For each [ProductNumber], its [Notes] are stored in an external text file
' called [ProductNumber].txt. The code below extracts the [ProductNumber] from
' the textfile into a string called [Prodno] e.g. if Notes textfile name is
' "ProductNumberX.txt", Prodno returns "ProductNumberX".
'How can I implement SQL or other condition below
'equivalent to UPDATE !Notes WITH [FileRead] WHERE ProductNumber = Prodno
!ProductNumber = Prodno
===========
Thanks so much for your assistance.
AbbyAnu.
I'm still learning VB, and I have some code that's giving me a headache.
table name: yeeken
Fields:
1. ProductNumber (primary field)
2. Notes (Memo field)
Each ProductNumber has a corresponding ProductNumber.txt file, which I wish to import into the [Notes] field, thus for example if the product number is ProdX, I would import the file ProdX.txt into the [Notes] field.
All the relevant .txt files are stored in one directory
========
Code:
Option Compare Database
Public Function GetPartData(FileLoc As String)
Dim FNames(), Prodno, FileRead As String
Dim StartPos, CalculatedNumber As Integer
Dim var As Variant
Dim i, j As Double
Dim db As Database
Dim Rst As DAO.Recordset
Set db = CurrentDb
Set Rst = db.OpenRecordset("yeeken", dbOpenDynaset)
If Not IsNull(var) Then
With Application.FileSearch
.LookIn = FileLoc
.SearchSubFolders = False
.FileName = "*.txt"
If .Execute() > 0 Then
j = .FoundFiles.Count
For i = 1 To j
ReDim Preserve FNames(i)
FNames(i) = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
StartPos = Len(FileLoc) + 2
For i = 1 To j
Close #1
Open FNames(i) For Input As #1
Input #1, FileRead
' called [ProductNumber].txt. The code below extracts the [ProductNumber] from
' the textfile into a string called [Prodno] e.g. if Notes textfile name is
' "ProductNumberX.txt", Prodno returns "ProductNumberX".
Code:
CalculatedNumber = InStr(StartPos, FNames(i), ".txt")
Prodno = Mid(FNames(i), StartPos, (CalculatedNumber - StartPos))
'equivalent to UPDATE !Notes WITH [FileRead] WHERE ProductNumber = Prodno
Code:
With Rst
.AddNew
Code:
!Notes = FileRead
On Error Resume Next
.Update
End With
Close #1
Next i
MsgBox "All Available Product Notes updated."
End Function
===========
Thanks so much for your assistance.
AbbyAnu.