Avatar of hidrau
hidrau
Flag for Brazil asked on

error on vba access function, ByRef

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"
     Else
        If Dir(strSourceFile) = vbNullString Then
           MsgBox "Não existe o arquivo de script na pasta padão!", vbOKOnly
        Else
          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"
    Else
       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
    Loop
    Close #intFileDesc    'Close file.
    
    
    Set qdf = Nothing
    Set dbs = Nothing     'Garbage handling before we exit the function

End Function

Open in new window


Why? How to solve that?
Thanks
Alex
Microsoft Access

Avatar of undefined
Last Comment
crystal (strive4peace) - Microsoft MVP, Access

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
als315

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
crystal (strive4peace) - Microsoft MVP, Access

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hidrau

ASKER
thanks a lot
crystal (strive4peace) - Microsoft MVP, Access

you're welcome ~ happy to help
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck