Solved

set column width on  print preview MIcrosoft access

Posted on 2013-11-28
7
1,392 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

728 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