Solved

set column width on  print preview MIcrosoft access

Posted on 2013-11-28
7
1,261 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 119

Expert Comment

by:Rey Obrero
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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now