This question involves 3 tables and 1 form in my Access database.
The tables are:
- Contacts
- Customers
- Contacts to Customers Relationship
The form is:
- Manage Contact
What I want. A list box that displays the output of this SQL query:
SELECT Customers.AccountName FROM Customers INNER JOIN [Contacts to Customers Relationship] ON Customers.MasAccountNumber=[Contacts to Customers Relationship].MasAccountNumber WHERE [Contacts to Customers Relationship].ID = 3 ORDER BY Customers.AccountName;
Where you see the "3" in the above SQL statement I would like to have a dynamic value there. Something that references the current records value for the ID column (Contacts table). If I have to do this in a VB script adjusting the list boxes RowSource where would I do that? onLoad for the form doesn't seem to make sense because when someone clicks to change records or add a new record I want it to update for that "Contact" (record).
Any help is appreciated.
TW
The resolution to this lies in using the forms Current() method. That causes the form to re-execute the query that is bound in the RowSource property for that list box each time a different record is accessed in the form.
Thank you for your response Mr. Fenton.
Related
I am creating forms in Visual Studio 2019 (using VB.Net) that is connected to a Microsoft Access Database.
From the image below, I have a parent form (i.e., Customer Database) with a key ID that is Customer Address. When I press the purchase history at the bottom, I can open a child form (i.e., Customer Purchase History). However, I do not know the specific code to write in the child form to filter the purchases for the current key ID.
In the example below, when I press "Purchase History", it shows the purchases of all customers and not of 1011 WESTON RD. The code that I currently use says
"Me.TblCustomerPurchaseHistoryTableAdapter.Fill(Me.CustdataDataSet.tblCustomerPurchaseHostory)"
Can anyone help me how to do the filtering for the child database? I will appreciate your help so much. Thank you!
enter image description here
First of all, you need a parameter to your table adapter. Click on your table adapter and select add query on your child form.
It will prompt out something like
Select Transdate, Customer,Qty,Price from CustomerPurchaseHistory (e.g)
then you add the parameter by extending the query
Select Transdate, Customer,Qty,Price from CustomerPurchaseHistory Where Customer = #Customer (e.g) and Name it as FillByCustomer on Top.
A new query will be created.
Then you probably have something like Me.TblCustomerPurchaseHistoryTableAdapter.FillByCustomer(Me.CustdataDataSet.tblCustomerPurchaseHostory, [Pass your customer Code here])
On your sub form
Declare a parameter something like
Public CustomerCode as string
(So that you can pass the parameter form your parent)
On your parent you can then do something like
frmChildform.show
frmChildform.CustomerCode = [Your selected custoemrcode]
After that on formload event on your childform just do something like
Me.TblCustomerPurchaseHistoryTableAdapter.FillByCustomer(Me.CustdataDataSet.tblCustomerPurchaseHostory, CustomerCode)
I'm making a research database & have about 20 (topical) Categories plus over 600 Subcategories. Selecting the category (as I type an entry) should narrow the options I can pick to the appropriate records from tblSubcategory. I made a tblSummary_Details where all the IDs connect my category entries with the entries of research themselves. I made a form called frmSubcategory with a CategoryId listbox & a cboCat-Subcat combo control. Using the lookup wizard, I can see all the Subcategory Ids in there, all the CategoryIds, & the names of the
Subcategories.
I also made a qryCat-Subcategory with this SQL statement:
SELECT
tblSubcategory.SubcategoryId, tblSubcategory.CategoryId AS Expr1,
tblSubcategory.Subcategory
FROM
tblSubcategory
INNER JOIN
tblCategory ON tblSubcategory.CategoryId = tblCategory.CategoryID
WHERE
(([frmSubcategory<CategoryId>]) = [frm.Expr1:CategoryId]"))
I feel my ability to follow instructions breaks down more as I get to the end of this SQL statement & I really don't know what I'm doing any more. I NEED help & really appreciate anything you'll do. I want to return to the combo box in the form a result that would narrow the Id options & names of the subcategories to pick from, based on whichever category ID I input into this form, as I input records of research.
In a recipe database I have two tables. One has the ingredients of every recipe [Recipe_ingr] and the other the available measures and weight for every ingredient [Weight2].
When I input a new ingredient for a recipe, I would like to be able to choose the available units for only that specific food.
I have tried with this expression in the control field but it prompts me to choose first, and then the options remain the same for all the records, not changing dinamically according to the record ingredient code.
SELECT [Weight2].[Msre_Desc], [Weight2].[Gm_Wgt] FROM Weight2 WHERE Weight2.NDB_No Like Recipe_Ingr.NDB_No ORDER BY [Msre_Desc], [Gm_Wgt];
Picture of my tables
Update:
I tried the syntax change suggested by June9 but still the control doesn't update automatically with every record as you can see in this picture: Table
Suggest you name controls different from fields they are bound to, like tbxNDB. The SQL needs to reference a field or control that is on the form. Also, LIKE operator without wildcard accomplishes nothing that an = sign wouldn't. Also recommend not using exactly same name for fields in multiple tables.
If you use that SQL statement in combobox RowSource, try:
SELECT Msre_Desc, Gm_Wgt FROM Weight2 WHERE NDB_No = [tbxNDB] ORDER BY Msre_Desc, Gm_Wgt;
You want to save Msre_Desc as foreign key, not a record id generated by autonumber?
I have an application that uses Oracle Apex 4.2 . It has a form ( form and report on a table) that needs to display descriptions for columns on the table. For instance, there is a column on the table called fund which has a numeric value ( 1 to 6). There is a separate table that gives a description for each of these 6 values. Under EDIT PAGE ITEM, under SOURCE, I chose SOURCE TYPE -> SQL QUERY
I entered this query below:
SELECT DESCRIPTION FROM
"#OWNER#"."BU19ANT",
"#OWNER#"."FUNDCD"
WHERE ANTFUNDCD = CODE
where BU19ANT is the table that used for this form
FUNDCD is the name of the look up table
ANTFUNDCD and CODE and numeric fields on the respective tables and DESCRIPTION is the value that I want to look up and display on the form.
This gives me the correct answer MOST of the time, but not all the time.
The key to the table ( and the field used to link from the report to the form) is the Soc Security Number. If I run this same query against the Oracle table hard coding the SS Number, I always get the correct answer.
This form has 5 look ups that work this way and they all have the same problem.
I assume that I DONT need to include the Social Security Number as part of the query Apex already knows that.
But I tried to add that and can not figure out how to code it.
I tried
WHERE ANTSOCIALSECURITYNUMBER ( column on table) = P2_SOCIALSECURITYNUMBER ( the item on this page)
but that gave this error
ORA-00904: "P2_SOCIALSECURITYNUMBER ": invalid identifier
Is there some other way to code this? Or to say where SS Number = current record?
Or am I on the wrong track here?
Try :P2_SOCIALSECURITYNUMBER (for items on session) or &P2_SOCIALSECURITYNUMBER. (for items on page)
I am using a Multiple Items Form to list CASES (records) where there is no TECHNICIAN assigned (Maybe I should use a Datasheet to list the records?).
I would like the user to select a TECHNICIAN from a dropdown field that gets its values from an Employee Table (I can do this). Then I would like the user to select multiple CASES (records) in order to assign that one TECHNICIAN to the Technician field in all of the selected CASES.
Basically, I'm trying to keep the user from having to assign a technician from within each and every incoming case request. I want them to "batch" assign a tech to multiple cases.
Can someone point me in the right direction?
Ok so I did some more research. This may not be the best answer but it works for now.
I created a Multiple Item Form.
I added an unbound dropbox that lists Employees from the table
I added a button on the detail section (for each record) with the follow line of code:
Me.Technician = Me.Choose_Technician
Now the user can pick a technician from the dropdown and then click the button to assign that technician to the record/casefile.
This is a simple solution if you only have a couple of records/casefiles to assign. If the amount of incoming casefiles increases there will have to be a way to select multiple records using the shift key. I'll keep researching this.