This is related to another thread on having a continuous form with checkbox control to select records, transpose each one and save to a csv. That is here: thread702-1678266
Now I am trying to make it so that I don't have to have a prompt for the path, everytime we go to make these files in a given project.
I created a new table called tblCustomPaths. It has a PK ID field, a field for the project ID, and the path.
What I want to do is have a text box control on the header for the path to be entered. It will actually be bound to that path column in the tblCustomPaths table. The after event of that text box (or change) would be set to the combo row/source filter that is also in the header of this form.
I am still working through that setup. The issue at the moment, is that I need to run some checks when the command button is clicked to cycle through the checked items and make the csv files.
I need to check that text box and if it is empty - msgbox to say "need to fill a path" and cancel event. If the directory doesn't exist, create it, if all is good, go do the loop.
I have the code below, but I get an error "Object Required". I have also gotten file/access error, but not getting that right now.
found this online:
This is my code, which I got some help from the awesome people on this forum:
Can anyone help me with this, please?
misscrf
It is never too late to become what you could have been ~ George Eliot
Now I am trying to make it so that I don't have to have a prompt for the path, everytime we go to make these files in a given project.
I created a new table called tblCustomPaths. It has a PK ID field, a field for the project ID, and the path.
What I want to do is have a text box control on the header for the path to be entered. It will actually be bound to that path column in the tblCustomPaths table. The after event of that text box (or change) would be set to the combo row/source filter that is also in the header of this form.
I am still working through that setup. The issue at the moment, is that I need to run some checks when the command button is clicked to cycle through the checked items and make the csv files.
I need to check that text box and if it is empty - msgbox to say "need to fill a path" and cancel event. If the directory doesn't exist, create it, if all is good, go do the loop.
I have the code below, but I get an error "Object Required". I have also gotten file/access error, but not getting that right now.
found this online:
Code:
Function FileExistsDIR(sFile As String) As Boolean
FileExistsDIR = True
If Dir$(sFile) = vbNullString Then FileExistsDIR = False
End Function
This is my code, which I got some help from the awesome people on this forum:
Code:
Private Sub cmdGenerateProjectMetadata_Click()
On Error GoTo Err_cmdGenerateProjectMetadata_Click
Dim strDoc As String
Dim strFileName As String
Dim strPath As String
Dim strExportFile As String
Dim rs As DAO.Recordset
Set rs = Me.Recordset
Dim bExists As Boolean
bExists = FileExistsDIR("path")
If Me.CustomPath = "" Then
MsgBox "You must enter a valid UNC path into the Custom Metadata Path, for files to be generated!!!", vbCritical, "Where am I putting the metadata?"
DoCmd.CancelEvent
ElseIf Me.CustomPath Is Null Then
MsgBox "You must enter a valid UNC path into the Custom Metadata Path, for files to be generated!!!", vbCritical, "Where am I putting the metadata?"
DoCmd.CancelEvent
Else
strPath = Me.CustomPath & "\"
End If
If bExist = False Then
'create directory
MkDir strPath
End If
rs.MoveFirst
For i = 1 To rs.RecordCount
If Me.GenerateMetadatatmp.Value = True Then
strDoc = "qryUnionCustomMetadata"
strFileName = Forms![frmProcessingTracking].Form![ProjectEvidenceFileBatch]
strExportFile = strPath & strFileName & ".csv"
MsgBox strExportFile
' This will not over write a file that already exists! Comment out to over write files!
If Not FileExists(strExportFile) Then
'Keep the next line no matter what
DoCmd.TransferText acExportDelim, , strDoc, strExportFile, False
' This will not over write a file that already exists! Comment out to over write files!
End If
End If
rs.MoveNext
Next i
DoCmd.SetWarnings False
strSql = "UPDATE tblDiscoveryProcessing SET GenerateMetadatatmp = 0;"
DoCmd.RunSQL strSql
Me.Requery
DoCmd.SetWarnings True
MsgBox "All custom Metadata has been generated", vbOKOnly, "Custom Metadata Generated"
Exit_cmdGenerateProjectMetadata_Click:
Exit Sub
Err_cmdGenerateProjectMetadata_Click:
MsgBox Err.Description
Resume Exit_cmdGenerateProjectMetadata_Click
End Sub
Can anyone help me with this, please?
misscrf
It is never too late to become what you could have been ~ George Eliot