ODBC Import with filename in a directory
Forums
Hi Brain,
How are you? Is it possible to help me a second time :)
Thanks again for your answer on my previews question. I have a new one that is driving me bonkers!
I have got Visual FoxPro files that need to be imported so that i can join a couple of tables. Visual FoxPro Databases are controlled by a DBC file that changes every time. Importing is only possible with the ODBC connection and that is working perfectly.
I have scripted the steps to import the tables and i am now trying to find the filename in the folder and include the filename and directory in the ODBC syntax. I am now stuck at the last step for the last couple of days and it is driving me crazy.
I reused some script on this website.
I included the script with the lookup in the ODBC syntax for the directory and the filename.
I icluded also the same script with fixed name in the ODBC syntax for the directory and the filename.
The script can locate the filename that is being searched in the private function but i cant include it in the ODBC syntax like the sAdminpad
There is only 1 .DBC file in every folder.
Can you see where it is going wrong?
Sorry for my poor scripting skills (i'm new to this)
Thanks in advance.
Dino.
Hi Brain,
Hi Brain,
No problem, i can understand if you have a personal life :)
My solution for this moment was to include the part of the code in the Sub Main. That way i could get the variable i needed (it gets lost after the loop in a function). I know it is not the most ellegant way of coding.
Can you help me with that my remaning questions?
Is there a simple command to delete all the databases in a project like the close all command "Client.CloseAll"?
How can i call this function from Sub Main? "Call bestandnaam_maken" is getting me a syntax error.
How can i call the variable "Txtpart" outside of the Function and for example in a different function or in Sub Main?
Function bestandsnaam_maken(currentValue As integer) As StringDo Until Txtteken = "\" Dim Txt As StringDim Txtpart As StringTxt = "tekst\text en iets ander.xlsx"CurrentValue = CurrentValue +1Txtpart =Right(Txt, CurrentValue)Txtteken=Left(Txtpart,1)Loop'MsgBox(Txtpart)End Function
Thanks in advance and have a good day.
Dino.
Hi Dino, here is some code to
Hi Dino, here is some code to delete all the IMD files in the project folder, you should use the Client.CloseAll before running this, if a file is open it will not get deleted but I haven't tested it out:
Option Explicit
Sub Main
Call deleteAllIMDFiles()
End Sub
Function deleteAllIMDFiles()
Dim objFSO As Object
Dim objFolder As Folder
Dim objFile As File
Dim task As task
Set objFSO = CreateObject("Scripting.FileSystemObject")
'make sure the folder exists
If objFSO.FolderExists(Client.WorkingDirectory) Then
'get the folder information, namely all the files from the folder
Set objFolder = objFSO.GetFolder(Client.WorkingDirectory)
On Error Resume Next
'the ProjectManagement task contains the code to delete files in the project folder
Set task = Client.ProjectManagement
'loop through all the files in the folder
For Each objFile In objFolder.Files
'make sure the files is an IDEA file
If Right(UCase(objFile), 3) = "IMD" Then
'delete the file
task.DeleteDatabase objFile
End If
Next
End If
client.RefreshFileExplorer
Set task = Nothing
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
End Function
Hi Brain,
Hi Brain,
I will try the code Thanks!
I think i found a solution for the second question by deleting the "currentValue As integer between the ()". It was not needed. Problem solved i think!
For the last part, see the code i included in the file.
If i call the msgbox within the function Text() the output in the msgbox is as expected "\example". When i call the variable "txtdeel" in sub main as part of the msgbox the output is empty where i expect "\example".
Hope this makes it a bit clearer.
Dino.
HI Dino, I think this is what
HI Dino, I think this is what you are looking for:
Sub Main
Dim Txtpart As String
Dim txt As String
Txt = "C:\test\example"
Txtpart = Text(Txt)
MsgBox Txtpart
End Sub
Function Text(Txt As String) As String
Dim txtdeel As String
txtdeel = iSplit(Txt, "", "\", 1, 1)
Text = txtdeel
End Function
Hi again,
Hi again,
Problem solved, after a day of debugging, i rewritten the part of the code that was not working and it is working fine now.
Thanks.
Dino.