I've looked through several pages on SF on this error. This is the first time I've tried to add records to Access via VBA. Here is my code:
Then I get this error: "Compile error: Expected user-defined type, not project"Option Compare Database Public Sub Retrieve_SOPS() ' Retrieve SOP files 'Record starting timer - BEGIN Dim StartTime As Double StartTime = Timer 'Set network folder path Const FolderPath As String = "\\JACKSONVILLE-DC\Common\SOP's for JV\SOPs Final" 'Instantiate FSO Dim oFSO As Object Dim oFolder As Object Dim oFiles As Object Dim oFile As Object Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(FolderPath) Set oFiles = oFolder.Files 'Instantiate DAO Dim db As DAO Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("tblSOP", dbOpenDynaset) Dim v As Variant 'Loop through each file in FSO For Each oFile In oFiles 'Remove temporary/hidden files If (oFile.Attributes And 2) <> 2 Then 'Split filename v = Split(oFile.Name, "-") ' Instantiate Necessary Variables Dim file_path As String Dim file_id As Integer Dim file_title As String Dim lang_code As String Dim creation_date As String file_path = oFile.Path file_id = v(2) file_title = v(4) lang_code = v(5) 'If dimension in array exists; Remove file extension If UBound(v) >= 6 Then creation_date = v(6) End If With rs .AddNew .Fields("file_path").Value = file_path .Fields("file_id").Value = file_id .Fields("file_title").Value = file_title .Fields("lang_code").Value = lang_code If UBound(v) >= 6 Then .Fields("creation_date").Value = creation_date End If End With End If 'Stop For Loop (TEMP) Exit Sub Next oFile End Sub
I'm reading "Microsoft Access 2019 Bible" By Wiley.



Reply With Quote
