Stepping through code

G

Guest

Hi,

I have written some code that I want to step through. From my limited
knowledge of Access there is no other way of running this code without using
a button (on click) to kick it off.

The reason I want to do this is to get the following code to run.


Private Sub LoadFile(sDir_and_Path As String)
On Error GoTo Macro1_Err

DoCmd.TransferText acImportDelim, "PO_Spec", "Tbl_PO_Listing",
sDir_and_Path

Macro1_Exit:
Exit Sub
Macro1_Err:
MsgBox sFile & ": " & Error$
Resume Macro1_Exit
End Sub

Public Sub I_LoadFiles(sDir_and_Path As String)
Dim dbsStatus As Database
Dim rstFiles As Recordset
Dim StrReq As String
Dim dTDate As Date

DoCmd.SetWarnings False
Set dbsStatus = CurrentDb
StrReq = "SELECT * FROM Tbl_Filenames"
Set rstFiles = dbsStatus.OpenRecordset(StrReq)

With rstFiles
Do While Not .EOF
If !File.Import = True Then
Call LoadFile(sDir_and_Path)
End If
.MoveNext
Loop
.Close
End With
dbsStatus.Close

DoCmd.SetWarnings True
End Sub


I didn't write the code but I'm pretty sure I can degug itonce it gets going
but I can't get the module to start. I've tried to create a button with an
on-click procedure and then for that procedure to call LoadFiles but I get
the following error.

The expression on-click you entered as the event propert setting produced
the following error: Procedure declaration does not match description of
event or procedure having the same name.

Is there an easy way to simply point the button to the LoadFiles code?

I'm expecting the code will look at a list of files in a table
(Tbl_Filenames) and import the contents into another table 'Tbl_PO_Listing'.
 
B

Brendan Reynolds

You can run a public procedure defined in a standard module by typing its
name followed by any required arguments in the Immediate Window. Press
Ctrl+G to open the Immediate Window and enter something like ...

I_LoadFiles "C:\SomeFolder"

Note that I'm only guessing here as to what sort of value the argument is
supposed to contain.

Looking at the code, this line looks dodgy ...

If !File.Import = True Then

The "." character is not a legal character in a field name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top