Solved

set column width on  print preview MIcrosoft access

Posted on 2013-11-28
7
1,317 Views
Last Modified: 2013-12-02
Hi,
i have a table as subform and when i am loading it i set the Column Width but when i  am printing the form the Width falls back to defaults how can i get over it?

any help would be appreciated !
0
Comment
Question by:yidel718
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39684093
did you save the form after setting the column width?

anyway for printing purposes, you normally use a report not the form
0
 
LVL 1

Author Comment

by:yidel718
ID: 39684099
I tried using the save button but no helps even the cursor in the the table (subf
0
 
LVL 84
ID: 39685008
i have a table as subform
This is generally a bad idea, since this essentially removes quite a bit of the event handling you would have when using a Form as a Subform. You're much better off creating a form based on that table, and then embedding that form in the mainform. You can set the form to Datasheet view, or create a continuous form that looks like a datasheet, and have the same experience for the user.

To reiterate what cap said: use a report for printing. Forms don't have the same event model or properties as reports, so they don't print correctly in most cases.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 1

Author Comment

by:yidel718
ID: 39685396
I can't use a form as the fields are dynamic
0
 
LVL 21
ID: 39686187

I can't use a form as the fields are dynamic
Why not?  I work with dynamic recordsets with a varying number of  columns in both forms and reports.

An alternative:
You might consider using Excel Automation. You can export the data into an Excel worksheet and format the columns as needed before printr5ing.
0
 
LVL 1

Author Comment

by:yidel718
ID: 39688297
Why not?  I work with dynamic recordsets with a varying number of  columns in both forms and reports.

i would be interest in understanding how you doing it !

An alternative:
You might consider using Excel Automation. You can export the data into an Excel worksheet and format the columns as needed before printr5ing.

Thanks for this alternative, but i would like to do everything access yet !
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39689571
I can't use a form as the fields are dynamic
If you're using a Table, then the fields aren't really dynamic, unless you're constantly changing that table (and field names).

Even then, you can still create a form on dynamic recordsets. Create a form with the number of controls you think you'll use, and name them something like "txt0", "txt1", "txt2", etc. The intent is to have them sequenced.

Now in the Open or Load event of the Form, do this:

Dim rst AS DAO.Recordset
Dim fld As DAO.Field

Set rst = Currentdb.OpenRecordset("Your SQL Here")

Dim i As Integer

For Each fld in rst.Fields
  Me.Controls("txt" & Cstr(i)).ControlSource = fld.Name
  '/ If you need to set the accompanying Label
  Me.Controls("txt" & Cstr(i)).Controls(0) = fld.Name
  i = i +1
Next

'/ now hide the rest
Dim J as Integer
j = i - 1

For j = i - 1 to Me.Controls.Count
  Me.Controls("txt" & cstr(j)).Visible = False
Next

Open in new window

This is air code so if you have issues please let me know, or HTC might have something that works better.

Notes:

For the sql of the Recordset, you can use several methods. You can pass that value in through the Form OpenArgs method. I like to include a hidden form in the project that has a Textbox named something like "txtSQL_YourFormName", and have the code refer to that when opening.  You'd first set that value, then open the form, so:

Forms("MyHiddenForm").txtSQL_fCustomers = "SELECT * FROM Customers WHERE Customer_Type=3"

DoCmd.OpenForm "MyFormName"

Open in new window

0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question