Solved

set column width on  print preview MIcrosoft access

Posted on 2013-11-28
7
1,226 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

759 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

20 Experts available now in Live!

Get 1:1 Help Now