PDA

View Full Version : VBA CODE FOR ACCESS 2013



nicdneil
06-24-2015, 11:35 AM
Hi! I'm a new subscriber.
I've been tasked with building an Access (2013) database. A Small group of us will use it. I'm at the point that I need code or a macro to simplify a step in the data process.
Basically, I have created a form containing a subform. The subform exceeds a legal size of paper; however, if certain columns are hidden prior to printing, it will fit a legal size of paper. I want to create a button that will both hide and then unhide certain columns to facilitate printing and pdf export.

The subform name is: "frm PAYSTUB- Gildan Subform"

The column names are:
CONTRACTOR NAME
GILDAN SOLO RATE
GILDAN TEAM RATE
GILDAN HOURLY RATE
GILDAN PICK RATE
GILDAN OT RATE

Can you help me?! :-) Many Thanks! Nic Neil

jonh
06-25-2015, 10:21 AM
add a listbox with your column names in and in the double click event add (I'm not at a pc so this might not be 100% right and I'm guessing the columns are controls displayed as a datagrid rather than fields from a table or query.)

Me!mysubform.form.controls(mylistbox.value).visible = Not Me!mysubform.form.controls(mylistbox.value).visible

Obviously replacing mysubform, mylistbox with your control names.

nicdneil
06-26-2015, 12:11 PM
Hello!
Thanks for the reply. The other users who access this database are not as familiar with Access. So, what we are really needing is a button they can click on to hide the columns, then export the file to pdf version, then unhide the columns for the next user.

Can you help me with creating code for a button to hide the 6 columns and then unhide after printing?

jonh
06-26-2015, 01:09 PM
Did you try the code? It should toggle visibility.

You could put it into subs, like


Sub mylistbox doubleclick()
Hidefield mylistbox.value
OutputPDF
Hidefield mylistbox.value
End sub

Sub hidefld(field as string)
Me!mysubform.form.controls(field).visible = Not Me!mysubform.form.controls(field).visible
End sub

SamT
06-26-2015, 04:06 PM
Sub CommandButton_MakePDF_click()
'Jonh's code
Hidefield mylistbox.value

'Code to Make Pdf file here

Hidefield mylistbox.value
End Sub

Sub hidefield()
'Sets the value of "Hidden" to the opposite of a controls .hidden value
Dim Hidden As Boolean

Hidden = Not Me!mysubform.form.controls(field1.Name).visible

Me!mysubform.form.controls(field1.Name).visible = hidden
Me!mysubform.form.controls(field2.Name).visible = hidden

End Sub

I am clueless about Access's Object Model, so you will have to modify the code to suit Access

nicdneil
06-29-2015, 09:49 AM
hi jonh! ok, i am going to try this again today...Ive been out of the office until today. thanks. i'll be in touch!

nicdneil
06-29-2015, 09:50 AM
hi samt! ok, i am going to try this again today...Ive been out of the office until today. thanks. i'll be in touch!