Print Recordset To File

Sep 28, 2005

hi guys,

i'm trying to run a recordset and export the string of each record into a txt file. from all the examples ive seen the way i'm doing it is right but i'm not getting any data to go into the actual file. my loop works perfect (as i watched it in debug mode) and it makes the string, my file just isnt getting outputted.

heres the code:

Private Sub btneParcel_Click()

Dim rs As Recordset
Dim strContents As String
Dim lngFileNum As Long
Const strFileName = "g:worksdatImport01.txt"

Set rs = CurrentDb.OpenRecordset("SELECT * FROM QryeParcelExport")
If rs.RecordCount > 0 Then

'header lines
strContents = "ISA*" & Format(Now, "yyyymmdd") & "*" & Format(Now, "hhnnss")
strContents = strContents & vbCr & "GS*CN"

Do While Not rs.EOF
'detail
strContents = strContents & "ST*"
strContents = strContents & vbCr & "CN*" & rs("EntryDate") & "*" & rs("EntryTime") & "*E*" & rs("CustId") & "*" & rs("CustName") & "*" & rs("CustAddr1") & "*" & rs("CustAddr2") & "*" & rs("CustAddr3") & "*" & rs("CustCountry") & "*" & rs("CustPhone") & "*" & rs("ChargeAcctNo")


rs.MoveNext
Loop

'footer
strContents = strContents & "GE*8"
strContents = strContents & vbCr & "IEA*36"


lngFileNum = FreeFile
Open strFileName For Output As #lngFileNum
Print #lngFileNum, strContents
Close #lngFileNum

MsgBox "Client Data has been successfully exported to G:Import01.txt", vbExclamation


End If

End Sub

anyone able to help with this? actually just reading my code, do i need another new line at the end of my string? think parts are going to one massive line that should be seperate lines...but that should still output something.

View Replies


ADVERTISEMENT

I Want To Print A Report And Programmatically Set The Printer Name And 'Print To File

Jul 16, 2007

How can I print a report and at the same time programatically set the printer name and 'Print to File' option and set the path of this option?

View 1 Replies View Related

Modules & VBA :: Print Current Record From Recordset?

Aug 7, 2015

Is there a way to print the current record from a dao.recordset?

This is an exercise to compare data content.

I have a table with 30 fields and thousands of rows (rs1).

I'm comparing it with a copy of the same table (rs2) that has the same number of fields and the same rows and almost the same content.

I can loop through the recordsets and get the cursor to stop on a field whose values don't match, lets say on row #x

and the programmed message will say something like:

"ROW: 699 Field: [RequestStatus] rs1.VALUE: Closed, DOES NOT MATCH rs2.Value: VOID, in the comparison recordset"Then I'd like to print the entire Row, Row #699.

I thought I could use rs1.getrows but I'm not sure how to make that work.

View 4 Replies View Related

Print Excel File

Dec 6, 2005

Hello, I'm back again.

I have this form with an button on it, but I like to know how to use the button for printing an Excel file.

Tnx,

Dinus.

View 4 Replies View Related

VBA To Locate A File And Print It

Dec 19, 2013

I'm very new to Access and especially VBA. How to get started with the correct syntax for locating a file, and printing it. The file will be a PDF and if possible I would like to declare a variable for the file name (not the path) so if it is changed I can just change the variable instead of looking for it in the code. I plan to have 10 of these.

View 6 Replies View Related

Disable File-->Print Option

Dec 12, 2006

I have a Print button on a form, which actually prints off a report for the user.
Some of them seem to be trying File-->Print, which actually just prints the form instead of the report and no matter how many times I've told them to use the Print button, they seem incapable of remembering.

Is there a way to turn off the File-->Print option ?

View 1 Replies View Related

Modules & VBA :: Appending To Existing Excel File From Recordset

Apr 18, 2014

I'm spinning my wheels on this. Trying to copy a recordset into an existing excel file.

Private Sub cmdExport_Click()

Dim conn As ADODB.Connection
Dim conn2 As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim strConnection2 As String
Dim wks As Excel.Worksheet

[code]...

View 2 Replies View Related

Modules & VBA :: Reading Table Of Information Recordset From XLSX File

Mar 17, 2014

I am trying to use a Connection to an xlsx spredsheet to read in a table of information (the data is not a table, just laid out in a table, see attached, the one I am trying to load is xlsx not xls but I cannot for some reson upload the xlsx one on here)

I have the following declared:

Code:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

my connection string is:

Code:
strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & cstrFolder &
Chr(92) & tempSymbol & ".xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES';"

I open the connection which works fine:

Code : cn.Open strConnectionString

Now here I hit the problem, I have the following SQL string:

Code : strSelect = "SELECT * from [table$]"

The spreadsheet contains just 1 tab, named table so I think I am referring to the data correctly in my SQL string?

When I open the recordet for variable rs using:

Code : rs.Open strSelect, cn, adOpenStatic, adLockOptimistic, adCmdText

I get the error dialogue box:

The Microsoft Access database engine could not find the object 'table$'. make sure the object exists and that you spell its name and the path name correctly.....

I did a Debug.print to check the strConnectionString was correct and the Source is exactly correct and refers to the name of the file I am trying to access exactly.

View 2 Replies View Related

Macro - Print To Adobe PDF File And Save As Database Name

Dec 16, 2004

Using Access 2000, I have a macro to generate a report by updating various make-table queiries. I would like for the macro to print the report to an Adobe PDF file and save the file as the database name.

When I manually print the report, it gives me the opition of selecting printers and Adobe PDF is listed as a printer. After selecting the "printer", a "Save As PDF" menu pops up and currently it lists the Access Report Name. I would like to use the database name as the name of the PDF file.

In short, when I execute the "Generate Report" macro, I want the end product to be a PDF file using the database name as the PDF file name.

View 6 Replies View Related

Reports :: Output / Print Results Of A Query To Text File

Dec 13, 2013

I have researched on here how to print the results of a query to a text file. I put the code in and I get an error on the openrecordset line. The error says "too few parameters, expected 4"

I tried the query in another report I export to excel and the query works.

I tried printing the whole table using "Select * from tbl_Customers" and it works????

Here is the code:

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("qryBell1", dbOpenSnapshot)
Dim fs, TextFile
Set fs = CreateObject("Scripting.FileSystemObject")
Set TextFile = fs.CreateTextFile(pathname, True)

[Code] ....

the query returns 6 fields for printing and can filter based on whether 3 fields are filled or not on the form - Date, Campaign, Status

View 6 Replies View Related

Modules & VBA :: Text File Split Into Table - Find Text In Recordset

Sep 5, 2013

I have some vba where I'm importing a text file and splitting it out into a table. For the most part its working just fine.

But I have a line of data that I need to pull out the string right after "Old" - Murphy and right after "New" ZMurphy

Acc# : 111111 This is test data, Person : 22222 Old Murphy New ZMurphy

I'm thinking Instr() could do this but I'm unable to get it to work.

I am using Access 2010...

View 3 Replies View Related

Modules & VBA :: How To Append Text To A Text File With The Print Statement

Jun 5, 2013

I'm trying to figure out at what point an error message occurs while a database is closing. This problem only occurs if someone clicks on the red close button on the top right of the screen when there are several forms open. If the user exists normally there is NO problem.

I am attempting to use the print statement to write to a text file to track what is happening as the database shuts down. Unfortunately, the open (print) statement, when issued, zaps any prior contents which precludes having a full printed record. I am hoping for a print syntax that would allow appending.

Code:
Open "ErrorReport.txt" for Output as #1
Appended text to the file to show what is happening in that event.
Close #1

The program, in closing, does stop with an error message that a certain file can't be found. But when I click on debug, the program simply closes. I have also commented out VBA references to the file that can't be found, but the error still persists .

View 2 Replies View Related

Modules & VBA :: How To Extract Recordset From Subform Into Recordset Object

Aug 14, 2015

Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.

The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.

The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.

The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.

Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?

Note: Immediate Window - One single field can be returned quickly

There are 48 fields that need validation - is there a way to reference the entire recordset?

Immediate Window during Break Mode:
? me.fsubsrNavSHLBHL("NavSH_QQ")
NESE ' this is the correct value for the current recordsource

Set a breakpoint right after the line:
fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value

Immediate Window:
? me.fsubsrNavSHLBHL.Form.RecordSource
Select * from vsrNavigatorSHLBHL where Well_ID =91229

View 4 Replies View Related

How To Hide Or Disable Print Or Quick Print Options

Dec 4, 2014

I have a form which my company wanted that each single record should be printed from form. I made a print record button and put code to print single page or record. However as a natural habit people go to file > print to print which leads printing all records so 1000's records start printing. Is there any way i can hide print button. File >Print button.

View 1 Replies View Related

Does A Filtered Mdb Recordset Still Bring Down The Whole Recordset?

Apr 27, 2007

Hi guys, I'm a bit confused: I know that opening a bound form will bring down the whole recordset. But if I create a parametered query as the recordsource, will it still bring down the whole recordset first and only afterwards cut down to the records matching the parameters?

Example: I have a clients table with 5000 clients on a backend mdb, and my client lookup form in my frontend mdb. If I open the form looking for just client "Jim Jones" (via the parameter query), will Access bring down all 5000 clients from the backend to my frontend first, and only then seek out "Jim Jones" before discarding the rest of the recordset?

For if this is true then this whole Access business is rather unsuited for networks, even a small one. I hope you guys prove me wrong.

Premy

View 14 Replies View Related

Modules & VBA :: Can Use Result Of One Recordset For Other Recordset

Jul 7, 2013

I want to write a email where there are 2 or 3 different ordernumbers for same email, i want to include the email in the mail part as single column table. how to do it? also can i use result of one recordset for other recordset?

View 1 Replies View Related

Reports :: Unbound Report - Print Preview OK But None Of Fields Print When Report Directly Send To Printer

May 25, 2013

I have an unbound form with an associated report. When the user hits the 'print' button on the form/screen, the report is launched in the background. In the On Load event of the report I populate the report fields from the forms field as so:

Code:
Me.txtAddrMainLine2 = "NAME " & UCase([Forms]![frm_OrderRx].[txtPatientName])

This works like a charm as long as I call the report in Print Preview mode (i.e. with acViewPreview). But if I send the report directly to the printer, none of the fields print.

I've read about using other report events to populate the fields (e.g., On Format and On Print) and also something about using TempVars to pass the data. But I haven't read anything that's clear and definitive about the full answer.

View 3 Replies View Related

Create A Recordset From A Recordset

Aug 17, 2007

from a table with fields userID and Date (in which any userID has multiple records with different Date values, and other fields) i have built a select query based on Date = one specific value. can anyone give an explanation (for beginners), through a sample code, that expands the query recordset so that the new recordset includes all records per userID that qualified in the prior recordset? below is an example. thank you!

Table with records:
userID / Date
u1 / d1
u1 / d2
u2 / d1
u2 / d2
u3 / d2
...
1st Select Query (where Date = d1):
u1 / d1
u2 / d1

Desired 2nd Query based off 1st Query (where ?):
u1 / d1
u1 / d2
u2 / d1
u2 / d2

View 3 Replies View Related

Updating One Recordset Using Another Recordset?

Jan 21, 2015

I have two tables that have the exact same fields. In table1 I have records that need to be UPDATED into table2. I tried an Update query and out of 600 records only half of those got updated. In my update query I joined tbl1 and tbl2 by Location (LOC) I checked for Nulls, Blanks, spaces, you name it. I can't figure why they all didn't get updated. I created a SQL query and go the exact same results. Ideally, I would like to create something in VBA to do this. I do not have any forms linked to these tables. In all I have about 600 records and 15 different fields that need to be updated. My example is only for one field.

sql example below. Which is the Access Sql in the Query

sql = "UPDATE tbl2 INNER JOIN tbl1 ON tbl2.LOC = tbl2.LOC" & _
"SET tbl2.Name = tbl1!Name" & _
"WHERE (((tbl2.Name) Is Null));"

Example.

Table1
Field1.Names = John

Table2
Field1.Names = "Need to UPDATE the name 'John' here"

I tried the Recordset .EDIT but I couldn't get it to work using two tables.

View 4 Replies View Related

Forms :: (Upload File) Button Stopped Showing All File Types

Oct 7, 2013

I recently upgraded a DB from 2003 to 2013 and ran into the following problem.

I have a button that opens a file dialog box and allows the user to upload a file to a predetermined location (and store the address as a hyperlink). I borrowed this code from someone else on here and modified it slightly.

In any case, the button still works, but now when it opens it doesn't have an option for "All files" under file types. So I can upload MS Office files, text files, etc., but not PDF files which are by far the most common types my users upload.

Private Sub Command35_Click()
Dim dd As Integer
Dim fileDump As FileDialog
Set fileDump = Application.FileDialog(msoFileDialogOpen)
dd = fileDump.Show
Dim Yourroute As String
Dim yourrouteName
Yourroute = fileDump.SelectedItems(1)
yourrouteName = StrReverse(Yourroute)
yourrouteName = StrReverse(Mid(yourrouteName, 1, InStr(yourrouteName, "") - 1))
FileCopy Yourroute, "us170fp00dataWBO_Tool_RoomDrawings" & yourrouteName
Me.Drawing_Link = yourrouteName & " # us170fp00dataWBO_Tool_RoomDrawings" & yourrouteName
End Sub

View 1 Replies View Related

General :: Mail Merge Word File (using Data From Access File)

Mar 11, 2014

I often create contract using mail merge. I have an access file that I want to use as data source for word file. But it does not automatically.

Please download the attached file !

If there are 1 customer and 1 property, I do not need to do anything. Conversely, if there are many customers and many properties, I take time to manipulate.

Firstly, I open the word file. I have to copy and paste paragraphs that I want. Highlight of the original paragraphs is blue.

Secondly, I click 'Insert Word Field' -> select 'Next Record'.

In short, I wish to use VBA in access file to automatically perform the steps that I have outlined.

View 3 Replies View Related

General :: Forms And Queries In One ACCDB File - Path Setting To Linked Table File

Oct 5, 2014

I've got the forms and queries in one .accdb file and my tables in a separate .accdb file. The forms file links to the tables in the tables file. The tables file resides in a folder called simply enough C:acc_tables and thats where i browsed to (obviously) when i set up the linkage.

One of the users does not wish (for whatever goddamn reason) to create a C:acc_tables file to stick the tables file in , and wants the tables file in some other folder.. Unfortunately this user does not have the skills to delete the existing links and re-link to the tables file after putting it in the folder he wants.

Where in the file that holds the forms and and queries do i find the path setting to the tables linked file? Can it be changed without deleting links and then re-linking?

View 4 Replies View Related

Text File To MS Excel Multiple File Import Application

Jul 20, 2006

hello,

I would like to automate something presently done on a one-by-one basis. Here: a number of text files(containing data) are to be exported into an MS Excel file, with each text file to occupy a different worksheet. Presently, the idea is to use the Data/import external data/import data feature of MS Excel for importing the text files one-by-one into newly created worksheets(within the same workbook).

I would appreciate some advice on how to go about creating a useful MS Access application to achieve the above. I have checked the available Macros in MS Access, but I could not find one to suit my purpose. can anyone pls assist, on how I can get started?

Tokunbo

View 3 Replies View Related

Modules & VBA :: Determine Excel File Type Without Opening The File?

Aug 14, 2015

Question: Is it possible, using VBA, to determine the actual Excel file type without opening the file?

I receive data files from other departments. Seems like every time someone changes their download structure, I end up with file types that do not match the download extension (example: xlm file with a xls extension). The files can't even be opened because of this. I think I can fix it if I could figure out how to determine what the file type really is.

I'm using Office 2010.

View 3 Replies View Related

Forms :: Storing File Location And Opening File From A Form

Dec 5, 2014

i had a database that allowed me from a form to store a file location for a record on a form, so i any time i could access the record, and then open the file, usually a pdf, it wasnt stored as a hyperlink, but as long text

i made the mistake of not copying the files for safe keeping when i got a permanent position..i am now back self employed, i need to recreate the database.

View 4 Replies View Related

Modules & VBA :: File Open Dialog Does Not Allow Selection Of All File Types

Oct 4, 2013

I recently upgraded a DB from 2003 to 2013 and ran into the following problem.

I have a button that opens a file dialog box and allows the user to upload a file to a predetermined location (and store the address as a hyperlink). I borrowed this code from someone else on here and modified it slightly.

In any case, the button still works, but now when it opens it doesn't have an option for "All files" under file types. So I can upload MS Office files, text files, etc., but not PDF files which are by far the most common types my users upload.

Here's my code and a screenshot is attached.

Private Sub Command35_Click()
Dim dd As Integer
Dim fileDump As FileDialog
Set fileDump = Application.FileDialog(msoFileDialogOpen)
dd = fileDump.Show

[Code] ....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved