How can I add grid in access form?
I need to build a form contains of two grids and buttons to add,edit, delete the data in them.
Can I do this with out using a lot of VB code ?
You can likely achieve this without any code. You can create one large form, and then into that form drop in a datasheet or a continues form. (so you can drop two forms into the one larger form). In access these are called sub forms.
Thus a grid like this can be created without any code and such grids allow editing of data:
The follow thus have two sub forms placed in one larger form:
In above the left side is a listbox, but it could have well been a sub form (a data sheet, or a continues form). The right side is in fact a sub from (a continues form) since I wanted to have one column based on a check box.
To filter the two sub forms based on customerID, then
bind the main form to a table with customerid.
Then when you drop in the two sub forms, you set the link master/child settings. In fact the wizrard will do this. So perhaps you re-create the main form bound to a table with customerID. Then in design mode simply drag + drop in the two sub forms you created. The wizard should setup the link master/child settings for you.
Now, use this one line of code to open this main form:
Docmd.OpenForm "my main form",,,"customerid = " & lngCustID
This will result in the main form loading only the one record, and the two subform will ALSO be automatic filtered to only reocrds matching the customerID.
Related
I have a form whose main purpose is to contain a datasheet subform (the form provides a common visual theme across the pages as well as navigation buttons and sometimes selection criteria for the subform).
One of my subforms has a check box.
The user behavior will be to:
Open this form
Filter the datasheet according to some specification
Do something off-line involving, e.g., the ten visible line items
Check the field (yes/no field) on those ten line items to indicate that it's been done
What I'd like is for the user to be able to check one box that then checks all the visible boxes.
The challenge is that it must only be the visible ones, i.e. dependent on what filters are in place.
I tried to create a checkbox in the main form labeled "Check All" which runs code something like:
me.sfrmReport.Control.reported.value = me.chkCheckAll.value
But unfortunately, this only checked the active row, not all of them. I know I could run a query on the underlying table, but it would need to replicate the user filters.
In fact, what might be even cooler would be a "Check highlighted" box that checks the highlighted rows only.
But I think "Check all" would be better.
I tried to find this, but my searching skills failed me. I'd have thought this was something somewhat common, but perhaps I'm thinking about this incorrectly. I do note that there's a sum function which automatically sums just the filtered/visible rows in a datasheet, so the notion of interacting with just the visible rows is at least somewhat standard.
Well, the check all box certainly should not be on a "row". So one would assume that say beside the combo box, you place a check all box. (can't imagine that the button or code would be place on the row(s)).
So, say beside the combo box in your screen shot, you have a button called check all.
The code behind that button would/could be:
dim rst as dao.RecordSet
set rst = me.MySubForm.Form.RecordSetClone
rst.movefirst
do while rst.EOF = false
rst.edit
rst!ResultReported = true
rst.update
rst.moveNext
loop
me.MySubForm.Form.Refresh
So above will operate directly against the sub forms data source (current filtered recordset).
I "think" from your screen shot, the top part of the form (with combo) is the main form, and the sub form you have displayed is the sub form.
So, of course you will have to replace the name of the controls I used above, and also the field name for the check box.
So the format to get that recordset is:
me.MySubFormControlName.Form.RecordSetClone
and to fire off a refresh of the sub form after the code runs is of course.
me.MySubFormControlName.Form.Refresh
Note that intel-sense should work and help you. if the code does not compile, then don't try and run it until it compiles.
If you create a form on a table that has 1-M relationship with another table, MS-Access creates the form containing the fields of the "1" side as text boxe, etc. and for the M-Side, a tabular structure is created.
What is the name of the control representing the tabular structure? (it is some kind of a list but it is not like the list you select from the tool box!). This control does not have a click event. Why? It only has ON ENTER and ON LEAVE events, so how to capture the current row?
It is a form within the main form AKA sub-form. Although it appears to be a grid-view (Access call it datasheet view), it isn't. Therefore it does not have row based events. However, the sub-form has all the events like a normal form would.
There are few limitations in this "dataSheetView", no other controls are visible except text boxes. If you need a button, you must have a textbox with click events. Ideally place the textbox as first/last column so you have your action buttons.
Access also has a "ContinuousFormView" which can be decorated like a gridview with all custom controls. Again, they are forms and do not have row based events. Only control based or form based.
The object next to the question mark is a Subform/Subreport Container Control. As its name implies, it is a container that holds other objects which can be a table, query, form, or report. This control is also available for selection from the 'toolbox'.
Best to give the container control a name different from the object it holds, like ctrDocuments.
What do you mean by 'capture' the current row? A row is not referenced, fields and controls are referenced. Several ways to approach referencing fields and controls (if a form or report) of the dependent object. How depends on where you want to run the code. In a query? In the main form events? In the subform events? For example code in Click event of a button on the main form could be like:
strDoc = Me.ctrDocuments.DocPK
MS Access novice here with almost no VBA/SQL experience. I've created a database with tables, queries, forms, and reports that all function well together except a few select things I'm stuck on.
Purpose of changing to the below method: Currently, I have created three main report types, with different filter options for each report. AKA: there is a SEPARATE REPORT displaying each different filter option, even though the report contains the same root information. It'd be great to have one report that allows users to filter/group/sort multiple ways to streamline the reporting process.
I'd like to have a 'Filter' button on my Reports form that opens a pop-up window containing filter options via combo boxes. To clarify - the pop-up form has been created and I can easily add a 'Filter Options' button to the report form that opens the pop-up window.
The pop-up form has combo boxes with Control Sources related to the field names on the main table that the report pulls from, as well as buttons for 'Close', 'Apply Filters', and 'Clear Filters'.
What I need help with: getting the combo boxes to supply options as well as get the 'Apply Filters' button to actually work. The filter options need to pull from fields in one of the main tables, with no text entry allowed.
'Apply Filters' button needs to do the following:
Apply filters per combo box selections. Needs to be OK for Users to leave filters blank if they choose.
Gives User a preview of the report w/ applied filters
What you really want to do is close the report and re-open it using the Filter and Preview options. Look into DoCmd.OpenReport. You will have to convert your filter to an SQL language filter based on what he user selects but everything else is pretty straightforward.
So the way I would work this is build a criteria into the form query with a parameter surrounding your popup form's combo box
then in your form vba I'd write:
Private Sub Filter1_AfterUpdate()
DoCmd.Close acReport, "Rpt2_FWItemsDue_AllSubs"
DoCmd.OpenReport "Rpt2_FWItemsDue_AllSubs", A_PREVIEW
DoCmd.Maximize
End Sub
assuming the name of the control is "Filter1" and the name of your form is "Rpt2_FWItemsDue_AllSubs" and "Filter1" filters the "FW_SubName" in the report.
I have two sub forms embedded in control (the one that looks like a set of folders allowing you to change from tab to tab.. Sorry I don't know the name in English)..
Both sub forms are embedded on one sheet, I would like that immediately after executing a routine, I wrote on one of the subforms, that the set focus then goes to the other sub form.
For some strange reason I can't get it to work. The sub form and field I'm trying to go to are frmObjectives03 and Effective_date.
I tried:
Forms!frmObjectives03!Effective_date.Form.SetFocus
but it doesn't work.
I would appreciate any insight.
Thank you,
The control you speak of is a Tab control.
Because frmOjective03 is opened as a subform, it is not part of the Forms collection. Instead you can use Forms!MainForm!frmObjectives03.Form!Effective_date.SetFocus from anywhere, or Me!frmObjectives03.Form!Effective_date.SetFocus from within the main form or Me.Parent.Form!frmObjectives03.Form!Effective_date.SetFocus from the sibling subform.
If these are not working for you, please check the name of the subform control in your main form (because it may be Child17 instead of frmOjective03). Open the main form in design view, click on the subform ONCE and look in the Properties->Other->name.
I have a MS Access form with a Datasheet subform.
Using code, I change the ColumnHidden property of various of its columns.
But, when I close the form, I'm asked whether to save the table layout of the Datasheet's table.
How can I stop the form from asking the user to same the table layout continually?
Do I have no choice but to change the Datasheet to a regular subform?
If you are always hiding the same columns - create a query that only has the columns you want displayed and use that as the source of your subform.
If you still need some hidden fields (child keys, etc.) you will have to create a regular form. It's not too bad:
just base it on your table,
drag your columns onto the form (formatting, and placement doesn't matter)
set it to datasheet view
edit labels (these become column headings)
change the tab order (this controls the order the columns are displayed)
view the datasheet and hide the columns you want
save the form
add this form as a subform to the main form
I'm not sure there's an easy way to do this because Access saves a lot of properties with forms. If you were not using Datasheet view, you could hide the CLOSE button on the form and replace it with a command button to close the form with this code:
DoCmd.Close acForm, Me.Name, acSaveNo
But since it's a datasheet, you can't do that.
You might try embedding your datasheet as a subform in an unbound parent form, but I don't know if using the code above behind a command button on the parent form will or will not save the column widths to the embedded subform.
One solution would be to re-initialize the column widths in the OnLoad event of your datasheet. You could then open the form with acHidden, and in the OnLoad event, set the column widths to their correct values (you'll want to multiply inches times 1440 to get the twips value to assign to the column width properties), and at the end of the OnLoad, set Me.Hidden to False.
But that is, indeed, something of a pain in the butt.
I'm afraid it's one of the downsides of using datasheets, since there's no way to define a close command button that won't save end-user UI data.