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
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”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.
Our community of experts have been thoroughly vetted for their expertise and industry experience.