Compile error: User-defined type not defined

crayroge

New Member
Joined
Mar 17, 2020
Messages
9
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Hi, I am new to VBA scripting and I am running a form in access to pull a file from a folder. However because a corrupted database, I export the form to a new data base and now I am getting this error:
"Compile error: User-defined type not defined". Is something wrong with this logic? I just want this setup to where the folder name can be variable and that the file name can be variable as well.



VBA Code:
Option Compare Database


Function GetFolder(strPath As String, strPrompt As String) As String
' [URL='http://www.mrexcel.com/forum/excel-questions/294728-browse-folder-visual-basic-applications.html']Browse for a folder in VBA[/URL]

    Dim fldr As FileDialog
   
   
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    'msoFileDialogFilePicker
    sInitDir = CurDir ' Store initial directory
   
    With fldr
        .Title = strPrompt
        .AllowMultiSelect = False
        .InitialFileName = strPath
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
NextCode:
    GetFolder = sItem
    ChDrive sInitDir ' Return to the Initial Drive
    ChDir sInitDir ' Resets directory for Initial Drive

    Set fldr = Nothing

End Function


Sub Import_Files()


          
     Dim strFolder As String
     Dim varFile As Variant
    
    
     Dim strFileID As String
    
     Dim colFiles As Collection: Set colFiles = New Collection
    
  

     strFolder = GetFolder("", "Please select the paths of the files") & "\"
    
     varFile = Dir(strFolder & "\*.txt")
     While (varFile <> "")
        colFiles.Add varFile
        varFile = Dir
     Wend
   
     For Each file In colFiles


        'Debug.Print Right(file, 12)
      
              
        strClip = Left(Right(file, 12), 8)
       
        strYear = Left(strClip, 4)
        strMonth = Mid(strClip, 5, 2)
        strDay = Right(strClip, 2)
       
        dtFile = CDate(strMonth & "/" & strDay & "/" & strYear)
    
                      ' File name
        If InStr(1, file, "COL") > 0 Then
            strlocation = "AD3"
        ElseIf InStr(1, file, "PS") > 0 Then
            strlocation = "AD2"
        ElseIf InStr(1, file, "JAX") > 0 Then
                strlocation = "AD1"
        End If
       
        Debug.Print strlocation & "|" & dtFile & "|" & file
        
       DoCmd.TransferText acImportFixed, "AdeccoImport", "AdeccoPayroll", strFolder & "\" & file, False
       
        DoCmd.SetWarnings False
       
        DoCmd.RunSQL "UPDATE AdeccoPayroll SET AdeccoPayroll.FileDate = #" & dtFile & "# WHERE (((AdeccoPayroll.FileDate) Is Null));"
            DoCmd.RunSQL "UPDATE AdeccoPayroll SET AdeccoPayroll.FileName =  '" & strlocation & "' WHERE (((AdeccoPayroll.FileName ) Is Null));"

        DoCmd.SetWarnings True
       
       
       
Next ' File in folder
   
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
It sounds like your VBA project is missing a needed library reference. Do you have the Microsoft Office Object Library checked? (Tools -> Refererences...)

1586554003482.png
 
Upvote 0
Thanks but how do I open up the file to make that change?
 
Upvote 0
As I said in my previous reply:

Tools -> References...

Look for "Tools" in the VBA editor menu bar.
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top