?
Solved

set column width on  print preview MIcrosoft access

Posted on 2013-11-28
7
Medium Priority
?
1,436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 85
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

762 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