How to see the controlsource and the display source properties? - database

I have two tables, user and company, and I have a combo box in which I list all the companies I have in the company table. My question is, how to use databinding in foxpro to display the company name? When I save the information to the database, I only need to save the company ID; same for display, from the company ID I have in my user table, I would like to display the company name.
I tried using the properties :
CmbCompany.controlesource = myTable.companyID
cmbCompany.displaysource = myTable.companyName
but this doesn't work, I missing something!

Set the RowSource for the combo so that it puts the data you want to show in the first column, and the value you want to store in the second. Set BoundColumn to 2 and, if your ID field is numeric or integer, set BoundTo to .T.
I'd do all this in the property sheet, but something like this:
RowSourceType = 6-Fields
RowSource = Company.CompanyName, ID
BoundColumn = 2
BoundTo = .T.
ControlSource = MyTable.CompanyID
Tamar

Related

Apply query criteria based on parameters

I need to run a query in a MS Access Database providing some parameters from a form. Imagine the next example:
I have a form which contains:
CheckBox1 and Text1
CheckBox2 and Text2
Button (to run query)
Now imagine a query with two fields: ID, NAME.
I want to filter ID by Text1 only when CheckBox1 is enabled. If not, I want the query not to filter ID in any way (as if the 'query' input was empty).
In the same way, I want to filter NAME by Text2 only when CheckBox2 is enabled. If not, I want the query not to filter NAME in any way (just like ID before).
I've tried so many things for a couple of days and have sniffed tons of internet pages and still don't come up with a solution.
You can use a SQL query such as the following:
select * from YourTable t
where
([Forms]![YourForm]![CheckBox1] = False or t.ID = [Forms]![YourForm]![Text1]) and
([Forms]![YourForm]![CheckBox2] = False or t.NAME = [Forms]![YourForm]![Text2])
(Change YourTable to the name of your table and YourForm to the name of your form; t is merely an alias so that you only have to change the table name in one place in the code).

SSRS Pivot with Dynamic Columns

My Query is like below for Table...,
Create Table t_raw
(
Month nvarchar(255),
Name nvarchar(255),
Clear nvarchar(255),
Contact nvarchar(255),
Viewed nvarchar(255),
Clicks float
)
Insert Into t_raw values('Jan-18','ABC','DTC','dtc#mz.com','GM','2'),
('Feb-18','QSC','FMM','fmm#mp.com','AM','6'),
('Mar-18','ABC','DTC','lta#mz.com','OPS','9'),
('Jan-18','MHY','GNMA','gnma#sr.com','REP','3'),
('Feb-18','VRL','XLR','xlr#vn.com','TUC','5'),
('Mar-18','MHY','GNMA','gnma#sr.com','XEM','7'),
('Jan-18','ABC','DTC','mat#sd.com','SUD','2'),
('Feb-18','MHY','GNMA','mio#fr.com','AFT','4'),
('Mar-18','TOC','ADF','fin#yu.com','BPL','2')
Below is the table:
I am expecting the below output like below.
Can anybody help me achieve this desired output?
Create a blank report and create a Data Source and a Dataset to connect to the data. Add a Matrix to the report. Drag the Name fiield from the Dataset in the "Report Data" window to the first "Rows" field of the matrix and select the Month field using the field selector in the Columns header field. Select the Clicks field in the data cell under the Month header, this should automatically result in a Sum. In the properties window of the Month Column Group change the sort order to an expression like
=CDate(Fields!Month.Value)
Change the width of the Name field to be wide enough to contain the four columns Name, Clear, Contact and Viewed (I chose 12 cm).
Now, right-click the Name header cell and insert a table via context menu. Don't worry about the hights and add an additional column in that table.
Do the same in the Name data cell
The design should now look like this:
In the table next to the Month field (I'll refer to that as "header table"), remove the Data row (and associated groups, when asked):
Then in the table next to the Sum(Clicks) field (I'll refer to that as "data table"), remove in turn the header row:
These steps resolve the problem with the hights.
In the "header table", enter the column names and format them as desired. In the "data table", select the corresponding fields to display. In the properties of the Row Group "Details1" of the "data table". add all 4 fields in the correct order for grouping and sorting.
For the fist 3 fields in the "data table", use the Properties sheet to set the HideDuplicates property to the name of your Dataset.
For the Sum(Clicks) TextBox, set TextAlign to "Center" and VerticalAlign to "Middle".
Oh, and add a total for the Name group of the outer matrix, align everything as desired.
VoilĂ :
Added:
To merge the cells for Name, Clear and Contact do the following:
In the properties of row group "Details1" of the "data table", remove Name, Clear and Contact under Grouping and under Sorting properties, so only Viewed is left. Rename the group to Viewed.
Remove the first three columns of the "data table" (Name, Clear and Contact).
Right-clicking always the topmost row group of the "data table", successivly add parent groups for Contact, Clear and Name.

MS Access: How to make a drop-down menu offer values from one table, but making it set the value of a different field when user chooses one

I am using MS Access 2010 to create an inventory database, and I have a form for users to enter purchase/inventory data, which looks like this:
The data underlying this form is actually stored in four separate tables - [Food items], [Invoices], [Inventory], [Food purchase data]:
I am trying to figure out how to make it so that the "invoice ID" dropdown in the form presents the user with a list of all of the invoice IDs that are currently present in the [Invoices] table. But once they select an option from that list, I want the dropdown to set the Invoice ID field in the [Food purchase data] table to that number. Basically, I'm just trying to make sure that when orderers are entering data in the [Food purchase data] field they are only able to enter/select values that are valid Invoice IDs.
What is the simplest way to do this?
You can do this by adding some code to the After Update event of the invoice combo box.
You should set the bound column of the Invoice combo box to be the InvoiceID. You'll need the ID of the FoodPurchase record you want to set too.
Dim sql as string
If Nz(<InvoiceCombo.Value>,0) <> 0 Then
sql = "UPDATE <FoodPurchaseTable> SET <InvoiceID> = " & <InvoiceCombo.Value> & " "
sql = sql & "WHERE <FoodPurchaseID> = " & <FoodPurchaseRecordID> & " ;"
CurrentDB.Execute sql
End If
Change the items in the <>'s to match your controls and tables. The is the name of the field in the table and is the index of the record you're trying to set.

displayvalue, rowsource and rowsourcetype in foxpro 7

I have two tables customer and category, to make things simple I'll keep the structure simple :
customer
---------
id name categoryid
----------------------------------
1 joe 1
2 john 2
category
---------
categoryid categoryname
-----------------------------------
1 User
2 Admin
I have a form with customer name and some other info as text fields, and a combobox in which i would like to display the corresponding categoryname from category table.
knowing that i would like the customer table to always store the categoryid, how can i do this with foxpro databinding ? display the category name value, from category table, and store category id in customer table ?
In the form designer, combo box properties, set the RowSourceType = 2(Alias) and RowSource = "CateGory.Categoryname, CateGory.CategoryId", ControlSource = "Customer.Id", BoundColumn = 2
Also, you will want to add the tables to the DataEnvironment of the form.
In the data environment add the table which has the category which you want to view in customer form and use the category ID associated with it.
Use a combo box control to link as data source to the customer table field with the category ID, try using the combo box builder by right clicking your mouse while selecting the combo box on the form, after this is done.
Go to combo Lost Focus event and display by code the category name for the selected category in the combo box using something like this:
Getting the category and displaying it in label on form assuming that the category ID is integer:
Local iCatID As Integer
iCatID = ThisForm.Combo.Value
Select CategoryTable
Locate for iCatID = CategoryTable.CategID
IF Found()
ThisForm.Label.Caption = "Category " + Transform(CategoryTable.Category, "#T")
ThisForm.Refresh()
Else
Messagebox("Invalid Category !")
Endif
Try it out, hope it works for you.

Automatically set one to many id when adding items

I have two tables with the following (simplified) structure
person_availabilities (id, person_id)
persons (id)
that are related (a person can have many availabilities)
I have used the bake feature to create the current pages.
What I wish to do is go to a person's profile and click on "New Person Availability". The page will then go to the add person availabilities page and allow the user to input the data there.
The user should not have to find the person in a drop down list, which is the default way to select the identity of the person whose availability I'm setting.
When you go to a person's profile and then navigate to add page, try to pass the id of that person through url to that add page and then try following:
URL may be:
http://example.com/person_availabilities/add/2 // here 2 is the person id
In person_availabilities controller's add function try something like this:
function add($person_id = null) { // $person_id is the passed id. e.g $person_id = 2
$this->set('person_id', $person_id); // set the id to view
}
In view file the select box should automatically show the person whose availability you're using if the select field name is person_id i.e.
$this->Form->input('person_id');
If not then try selected property to that select box:
$this->Form->input('FIELD_NAME', array('selected' => $person_id));

Resources