MS Access subform to query based form populating wrong - ms-access-2010

I'm working on an Access database that has a main table that keeps track of basic user information and several sub-tables that have a one-to-many relationship to the main. Now all users are in one of two groups, which they can move between, and half of the tables only apply to one group. Which group a user is in is determined by a Boolean.
How I intended to set up the the various forms and sub-forms was to have the main form based on the queries:
SELECT *
FROM Foo
WHERE InGroup1 = TRUE
and
SELECT *
FROM Foo
WHERE InGroup1 = FALSE
and then add the appropriate sub-forms.
However, what keeps happening is that if there isn't a record in the sub-table associated with the currently selected ID of the main table, it just displays the first record in the table.
If I make a main form not based on a query it works fine, but then the two groups are mixed together.
Is there a way around this?

I cannot reproduce your problem. This is an example of a form and subform where the subform data does not contain a record for the main form. The main form is based on a query:
SELECT * FROM groups WHERE ingroup1 = true
And is built in MS Access 2010.

Related

How to get the selected Lookup value from a custom Lookup from ax2012

Dears,
I'm using Microsoft Dynamics AX2012 R3
The Case: I want to make a custom lookup in Inventory Management ==> Journals ==> Item Transactions ==> Movement ==> Lines
I want to relate the Item Id to show all lines in the SalesLines Table in order to get the ItemId and It's dimensions (Config/Size/Color/Style) and when I select it I want to move the selection to the movement line.
My Solution:
Step1: I've made a custom view (viewCustomItemId) that shows all SalesLines tables and related to InventDim to show the dimensions.
Step2: I've made a custom form (frmCustomItemId) and added the view (viewCustomItemId) as a datasource and added all fields to a grid
Step3: In the form (InventJournalMovement) I've overrided the lookup method and added below code
Args args = new Args();
viewCustomItemId _viewCustomItemId;
args.name(formstr(frmCustomItemId));
args.caller(element);
newPopup = classFactory.formRunClass(args);
this.performFormLookup(newPopup);
newPopup.init();
newPopup.wait();
if (newPopup.closedOk())
{
_viewCustomItemId = newPopup.docCursor();
InventJournalTrans.ItemId = _viewCustomItemId.ItemId;
InventDim.configId = _viewCustomItemId.configId;
InventDim.InventSizeId = _viewCustomItemId.InventSizeId;
InventDim.InventColorId = _viewCustomItemId.InventColorId;
InventDim.InventStyleId = _viewCustomItemId.InventStyleId;
InventJournalTrans_DS.research();
}
Problem: When the lookup form is closed all fields are set to the movement line but I get warning message (Field 'Item number' must be filled in.) and the line number in the database are set to be minus for this line and also the default site and warehouse for this Item is not automatically set.
Question: Looks like I've retrieved the values but didn't pass it correctly to the lookup of the field, I don't understand what exactly I missed to make it work normally.
Thanks in advance.
I'm surprised I missed this at first glance.
This line is your problem:
InventJournalTrans_DS.research();
You're researching before you've updated/written the data. I'm not sure why you're researching in the first place, but you have to do one or the other. Write/Update, then research or don't research. The research is where you're losing the ItemId you've input.

MS Access Form Not Showing Results

This is truly baffling.
I have a subform that is set up as a continuous form and receives data from a query. Here is the SQL
SELECT Top 12 Tbl_Parent_ITN.ID, Tbl_Parent_ITN.ITN_Number, Tbl_Child_ITN.ITN,
Tbl_Child_ITN.Parent_ITN_fk, Tbl_Scope_Rqmts.Completed, Tbl_Scope_Rqmts.Child_ITN_fk,
Tbl_Lkup_Requirements.Requirement, Tbl_Lkup_Basis.Basis
FROM Tbl_Parent_ITN INNER JOIN (Tbl_Lkup_Requirements
INNER JOIN (Tbl_Lkup_Basis INNER JOIN (Tbl_Child_ITN INNER JOIN Tbl_Scope_Rqmts
ON Tbl_Child_ITN.Id = Tbl_Scope_Rqmts.Child_ITN_fk) ON Tbl_Lkup_Basis.ID = Tbl_Scope_Rqmts.Basis_fk)
ON Tbl_Lkup_Requirements.ID = Tbl_Scope_Rqmts.Requirements_fk)
ON Tbl_Parent_ITN.ID = Tbl_Child_ITN.Parent_ITN_fk
WHERE (((Tbl_Parent_ITN.ID)=[Forms]![Frm_Parent_ITN_Main]![parent_id]));
The criteria in the where clause of the SQL is passed based on the control in the form that precedes this form. The value is the primary key of the parent table that joins with several child tables to get all of the data for the subform.
When I open the with one record that has children it works perfectly fine and the form populates with 12 records. However, when I go run the same operation on the next parent record I don't get any results in view even though that parent has 4 child records.
What is really perplexing is that when I run the query independently from opening the form it gives me the exact results that I want based on that 2nd parent record. Furthermore, if I change the subform to a datasheet I still don't get any records; however, I can see the results in the filters of the datasheet form if I select those column headers (but no records show in the form itself). The properties of the subform are the exact same in both cases, so I can't understand what would cause the records to show in the 1st case but not the 2nd??
A few suggestions:
1. Try to do a Me.Refresh to see what happens.
2. Put a break point in the form's OnError event to see is there is something wrong.
3. Check if there is any other data source that may be locking any data that should be refreshed.
4. Verify that the no properties that define the parent-child relationship of the data is being changed during runtime.
5. Check if the parent record id gets refreshed on the OnCurrent event of the form.
Hope this helps,
FunkSoulBrother

Choosing from multiple query results to display in a single form

I have a form that submits parameters to a query, then opens the resulting record in another form. The problem is, whenever there is more than one record it automatically puts the first one into the from without any kind of option to choose the record I want. I have a macro set up on the search button on the first form that submits the parameters to the query and then displays it in the second form, I've tried to set up another macro in between the two, but I don't know if it's possible to set up the expression creator to check the number of rows resulting from a query. Is it possible to modify the query to create a prompt to choose which record I want? Or should I change something else?
This is the query:(automatically created by access)
SELECT CHILD.CHILD_L_NAME, CHILD.CHILD_F_NAME, CHILD.DOB, CHILD.GENDER, CHILD.DAYS_IN_CARE,
CHILD.HOURS_PER_DAY, CHILD.ENROLLMENT_DATE, CHILD.CHILD_ADDRESS, CHILD.CHILD_CITY,
CHILD.CHILD_ZIP, CHILD.CHILD_STATE, CHILD.CLASSROOM, CHILD.SNACK, CHILD.LAST_UPDATED, CHILD.CIN
FROM CHILD
WHERE (((CHILD.CHILD_L_NAME)=[Forms]![Search]![L_NAME]) AND
((CHILD.CHILD_F_NAME)=[Forms]![Search]![F_NAME])) OR
(((CHILD.CHILD_L_NAME)=[Forms]![Search]![L_NAME]) AND
((CHILD.DOB)=[Forms]![Search]![DOB])) OR
(((CHILD.DOB)=[Forms]![Search]![DOB])) OR
(((CHILD.CHILD_L_NAME)=[Forms]![Search]![L_NAME]));
If I understood well your problem and you use VBA it's quite easy to do.
You can create a reduced query based on the query you're creating with the button. This new query should include all and only the fields that allows you to discriminate beetwen the records to show in the 2nd form.
For instance it could include LastName, FirstName and classroom to select between children with same full name.
You can count the number of records of this 2nd query and if greater than 1 it means that you have more than one children to show.
So you can use this 2nd query to populate a combo-box or a listbox for selecting the record you really want to show.
When number of records is 1 you can simply skip the listbox population using an if statement on recordcount.
Next step is opening the form with the selected (or unique) record.
Bye

Lookup field appears as numerical values instead of text on Access report

I am trying to create a report putting a field called contact which has the name of a person. This name is linked directly to another table where I keep all the contacts.
For some strange reason, when I include this name (which in query view displays as the name of the contact), instead of the name appearing, the unique ID number is shown on my report.
As mentioned in the article cited in the above comment, you can use a Combo Box control on your report to do the lookup for you. To see how this can be done, create a new report based on the table containing the lookup field, then drag and drop that field onto the report. That will create a Combo Box control with properties that look something like this:
Row Source: SELECT [Clients].[ID], [Clients].[LastName] FROM Clients;
Bound Column: 1
Column Count: 2
Column Widths: 0";1"
You could use a similar Combo Box control on your actual report to display the client's name rather than their numeric ID value.
Another alternative would be to change the Control Source of the report's Text Box control to have it do a DLookUp() on the table. If the lookup field is named [client] then changing the Control Source of the Text Box to something like
=DLookUp("LastName","Clients","ID=" & [client])
would also work.
I wanted to add to the great answer by Gord:
When using a "web" database (started in Access 2007 I think), you cannot change a report's fields to ComboBox style, nor can you use DLookUp(). (web databases lack a ton of features)
The workaround for this, if you want to create a Web-Report that uses lookup fields, is to create a Web-Query first based on your Web-Table (all the Web-* stuff has a www planet icon over the logo, if you create a new Web-DB in Access 2007+ you'll see what I mean)
So, instead of Table -> Report, you'll have to do W-Table -> W-Query -> W-Report.
Then, the only thing you need to customize to get the data right is the W-Query. Start by trying to reproduce the look in the query to match what you want users to see in the report. Note that here in the query, lookups will work fine (instead of the unique ID's, you get field names like you want). However, this will not carry over to the report. To do that, you gotta get the actual text field name you want into the query:
You should already have one table in your query; start by adding the table that your first lookup field points to. For example, the table I want to print is called Stock_Boards, and it has a lookup field called PCBID_lookup that points to the table Stock_PCBs.
Since you're using lookup fields, there should already be a relationship line between the two tables when you add the second one. If there isn't, something has gone horribly wrong.
Now, see how that line connects two fields on the two different tables? For example, I've got my PCBID_lookup field on my Stock_Boards table, which connects to the ID field on my Stock_PCBs table. If I created a report from this now, PCBID_lookup would be a number, a number that correlates to the ID of a record on Stock_PCBs.
To fix it, I will add the name field I want to show up on the report. In my example, that happens to be a Part Number, rather than the ID. I add the PartNumber field from my Stock_PCBs table to the query, and remove the PCBID_lookup field of the Stock_Boards table from my query.
Since PartNumber is what I want to show up on my report, it effectively replaces the original field (PCBID_lookup)
Repeat for all lookup fields you want in your report.
I had 1 more: I removed the Status field of the Stock_Boards table (which was an ID/Lookup) and added the 'Status' field from the Status table (which was the actual text name)
When finished, your query should look exactly how you want the data to appear, without any special tricks or asking Access to do something unnatural. Save your query, and create a web-report from it. Done!

Oracle APEX - If statement in database trigger

Ok. So I know how to create a trigger that makes changes to Table B when an action is made on Table A. that is reletively easy and I am comfortable doing so. What I have been unable to do is to create a trigger that contains an if statement so that it executes if certain criteria are met.
Example:
Table A & Table B are related. Table A contains data concerning documents that are currently in processing which are identified by a unique processing code. Table B contains data about finalized and released documents which are identified by a Publication ID. Table A and Table B are related because a document may undergo many revisions and therefore it may appear multiple times in Table A (unique processing code but same Publication ID) while still only appearing in Table B once. The Publication ID remains the same throughout the course of the document's life no matter how many revisions it undergoes.
Table A is filled via an input form where people submit requests concerning documents they would like to have us process. They have the option of selecting to process a new document or if they would like to revise a current document that is already in Table B. This is done via a radio group (New, Revision etc...). If 'Revision' is selected then a select list box, that is populated with Publication IDs from Table B, appears and the user can select which document to edit.
What I need to do is create a trigger, or some other means, that will, when a request is submitted via our input form, check to see if it is for a revision of a document in Table B and mark the 'Status' column in Table B to 'Revision in Progress'.
So it would need to be either conditionally called or have some kind of if statement in the trigger itself. The condition, again, would be if 'Revision' is selected on Table A's input form then set the Status of the selected Publication ID to 'Revision in Progress'.
Thanks!
It should be normal row level trigger on table A,
A pseudo code should be something like this..
create or replace trigger on table A for each row .....
if :NEW.process_selected = 'Revision' then
update b
set status = 'Revision in Progress'
where publication_id = :publication_id ;
end if;
end ;
-Sanjeev
It's been a long time since I used APEX, but can't the form submission be to a pl/sql procedure rather than directly to a table? Then write a procedure that takes the appropriate action depending on the input parameters.

Resources