troubleshooting Question

error on vba access function, ByRef

Avatar of hidrau
hidrauFlag for Brazil asked on
Microsoft Access
4 Comments2 Solutions197 ViewsLast Modified:
Hello Guys,

I have two function, the first function ask the user to informa a file.txt and then pass the file to the second function that have to open the file.
But access is complaining about it with " incompatible argument byRef"

Please, take a look at my code:

Private Sub Comando0_Click()
  Dim Message, Title, Default, MyValue
  If MsgBox("Deseja realmente rodar o script??", vbQuestion + vbYesNo, "Script") = vbYes Then
     Message = "Informe o script"       ' Set prompt.
     Title = "Execução de Script SQL"   ' Set title.
     Default = ""                       ' Set default.
     MyValue = InputBox(Message, Title, Default)
     If Trim(MyValue) = "" Then
        MsgBox "Script não informado, será pego o padrão da pasta!", vbOKOnly, "Execução de Script"
        If Dir(strSourceFile) = vbNullString Then
           MsgBox "Não existe o arquivo de script na pasta padão!", vbOKOnly
          Call ReadSql(MyValue)
        End If
     End If
  End If
End Sub

Public Function ReadSql(arq As String)
    Dim intFileDesc As Integer          'File descriptor for output file
    Dim strSourceFile As String         'Full path of source file
    Dim strTextLine As String           'Input buffer

    Set dbs = CurrentDb
    If arq = "" Then
       strSourceFile = "c:\access\script.sql"
       strSourceFile = arq
    End If
    If Dir(strSourceFile) = vbNullString Then
       MsgBox "Não existe o arquivo de script na pasta padão!", vbOKOnly
    End If
    intFileDesc = FreeFile
    Open strSourceFile For Input As #intFileDesc
    Do While Not EOF(intFileDesc)               ' Loop until end of file.
        Line Input #intFileDesc, strTextLine    ' Read line into buffer
        CurrentDb.Execute strTextLine
    Close #intFileDesc    'Close file.
    Set qdf = Nothing
    Set dbs = Nothing     'Garbage handling before we exit the function

End Function

Why? How to solve that?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros