Friday 15 May 2015

MA Access 2010 VBA code outputs in RUN cmd in macro but not off form button -


The following is called the MS Access 2010 macro. I can use the macro run command to run the routine and this is correct By way of form a file of data in the "c: \ EOW" folder and stores it. When I run a macro from a button on a form, it does exactly the same thing and the macro runs out as a run, but there is no file output because the macro is with the run method. Any advice is appreciated

Scott

The macro has a call in "ExportQueryToTxt (" MYOBWklyInvoices "," c: \ EOW \ MYOBWklyInvoices.txt ", 1," ")" and The VBA function is down;

  Option Databases Option Clear Public Function ExportQueryToTxt (ByVal as the data source string, compare the name of the _VerVal file as string, _ Optional DocIDIndex as Long = 0, _ Optional ByVal ListSeparator as string = ",") 'see http://www.dbforums.com/microsoft-access/1664379-automatically-adding-blank-lines-text-file.html' 'SMW Note: Definitely Does not work with a query with a parameter in 'if the query creates a table And use it 'Datasource: Select a table name, select a query or select a SQL statement' In any case, the russet should be sorted on the DocIdindex column. 'Filename: The name of the output file will be found which will be exported. I' docindex: The original location of the column in the document, in which the document ID (default = 0-> first column) is included. 'ListStyle: Used to isolate different columns of character data' in the text output file (default = ",") "Example of the call: ExportQueryToTxt" Qry_Export "," c: \ export.txt ", 1," ; "Dim DBS DAO.Database dim as DAO.Recordset slow first form DAO.Field dim intHandle as FLD integer string strline string dim varDocID version intHandle = FreeFile as Open FILENAME as output Use 'connect to lines' as the #intHandle for 'attach' in the existing file, if set to DBS = CurrentDb 'MsgBox ("Start") set first = dbs.OpenRecordset (Data Source)' SMW MYOB Field Name + Input Week Number Parameters with strLine Le line load = "ignore" strline = "invoice, customer po, details, account, zodiac, inc. Tax, supplier, journal memo, SP first name, tax code, GST amount, category, card ID" print #intHandle , Strline strline = "finish SMD with RST. The group changes anything in the same invoice or similar number togeher 'in sequential lines then inject a blank line when the varDocID = rst.Fields (DocIDIndex) .Value Do .OF for each until the FLD in the rst.Fields Lane (strLine) & gt; wth; 0 Then Strawline = Stretch & amp; List separator Strellin = Strawline & amp; Fld.Value Next if rst.Fields (DocIDIndex). Value & lt; & Gt; VarDocID then strLine = vbNewLine & amp; StrLine print #intHandle, strLine strLine = "Finish creating invoice" varDocID = rst.Fields (DocIDIndex) .Value .MoveNext with loop end then set .close termination first = nothing stop #intHandle MsgBox ('SMW advised when done Added "") for the end function    

You do not need to include the macro There is no need to do this, and usually it will not produce useful error messages (there may be a problem with nested quotes.)

To display a property sheet, click Find Event and type the following line directly in the following way:

  = ExportQueryToTxt ("MYOBWklyInvoices", "c: \ EOW \ MYOBWklyInvoices.txt", 1 , ",")   

require a similar-signal, and the surrounding quotes are not

add a simple messagebox to the function You can prove that it is going on.

No comments:

Post a Comment