I hope this goes here.

Alright, so I'm trying to write a simple program that takes the contents of a query's results and pastes them to a text file. Although I could do this manually, I'm trying to create a "user friendly" method for when I'm out of the office and someone else wants to do something.

So far, I've tried the following...

Private Sub Mailing_List_Click()
Dim Entry As String
Entry = "Whut?!"
Open "J:\James' Workbench\Tools\Mailing List.txt" For Output As #1
  Write #1, Entry
  Close #1
End Sub

I did this just to see how to go about opening, writing too and close the text file. It did not succeed.

What do I have to do? Create an object, open the text with that and write to it?

Dani AI

Generated

When a form button in Access appears to do nothing (even a MsgBox), two separate problems are most likely: the event procedure never runs, or code fails before it can show anything. The usual checks in order are: confirm the button's On Click is set to [Event Procedure]; make sure the VBA sub name exactly matches the control Name (for example a control named cmdMailingList needs Private Sub cmdMailingList_Click() in the form's class module); verify the procedure is in the form's module (not a standard module); compile the VBA project (Debug -> Compile) to reveal hidden compile errors; and look for MISSING references in the VBE (Tools -> References). If the database is not in a Trusted Location or macros are disabled, code may be blocked from running.

A quick diagnostic sequence: create a simple test button (e.g. cmdTest), set its On Click to [Event Procedure] and place a tiny routine that calls MsgBox "test" or contains a Stop to force a breakpoint. If that still does nothing, a broken reference or macro security is almost always the cause.

For exporting query results, Access has a built‑in exporter that avoids manual file handling:

' export a saved query to a delimited text file (includes field names)
DoCmd.TransferText acExportDelim, , "qryMyMailingList", "C:\Temp\MailingList.csv", True

If a custom layout is required (or the query is built at runtime), open the query as a DAO.Recordset and write lines with the FileSystemObject. Example pattern:

Sub ExportQueryToText(qName As String, outPath As String)
  Dim rs As DAO.Recordset
  Dim fso As Object, ts As Object
  Set rs = CurrentDb.OpenRecordset(qName)
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set ts = fso.CreateTextFile(outPath, True, False)
  Dim fld As DAO.Field, line As String
  ' header
  For Each fld In rs.Fields: line = line & fld.Name & ",": Next
  ts.WriteLine Left(line, Len(line)-1)
  ' rows
  Do While Not rs.EOF
    line = ""
    For Each fld In rs.Fields: line = line & Nz(rs(fld.Name), "") & ",": Next
    ts.WriteLine Left(line, Len(line)-1)
    rs.MoveNext
  Loop
  ts.Close: rs.Close
End Sub

Checklist: confirm control name / On Click linkage, compile the project, check Tools->References for "MISSING", verify the file path and write permissions (network drives can block writes), and ensure the DB is trusted. Given reported that even a MsgBox failed to appear, missing references or macro/trust settings are the highest-probability causes.

I hope this goes here.

Alright, so I'm trying to write a simple program that takes the contents of a query's results and pastes them to a text file. Although I could do this manually, I'm trying to create a "user friendly" method for when I'm out of the office and someone else wants to do something.

So far, I've tried the following...

Private Sub Mailing_List_Click()
Dim Entry As String
Entry = "Whut?!"
Open "J:\James' Workbench\Tools\Mailing List.txt" For Output As #1
  Write #1, Entry
  Close #1
End Sub

I did this just to see how to go about opening, writing too and close the text file. It did not succeed.

What do I have to do? Create an object, open the text with that and write to it?

Actually, my problem is even bigger than I thought. I cannot get anything to work when I click the button at all, even just a MsgBox.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.