Table row as column in Access form - sql

I am trying to create a form in Access based on a table and I would like to use the table's rowdata as the column title in the form.
What I mean is, I have a table as follows which shows the effort booked by employees towards specific projects on a monthly basis:
ProjectNo EmployeeName HoursBooked Month/Year
23 Mark 68 01/01/2012
23 Mark 55 01/02/2012
54 John 22 01/02/2012
23 John 52 01/02/2012
...etc
and from this I would like to create a singular form where the data is displayed as follows for each project. For example, for project 23:
Month/Year Mark John
01/01/2012 68 0
01/02/2012 55 52
and someone should be able to go to this form, edit the numbers and the table should reflect these changes.
Could someone guide me on how to achieve this? I have been trying to achieve this in Access but unfortunately my Forms knowledge is not that great.
Thanks!

Let say that 1st form is having name: FrmProject & project id is displayed in ProjectID control.
The second form is having name FrmProjectDetails. Considering that project data is stored in table TblPorjects.
On the Click event of ProjectID control in FrmProject you write the code as follow:
Private Sub ProjectID_Click()
docmd.open "FrmProjectDetails"
Form_FrmProjectDetails.RecordSource= "select * from TblProjects where ProjectID=" & Me.ProjectID
End Sub

Use the wizard to create a crosstab query. It will give you what you want. You can set the Source Object of Subform Control to Query.NameOfCrosstabQuery.
However, you will not be able to edit form data based on a crosstab.
It is possible that someone will see an alternative solution if you say why you wish to present the data in this way.
EDIT some details on a possible approach: http://wiki.lessthandot.com/index.php/Crosstabs%2C_forms_and_updating

Related

Conditionally Inserting another record in a mailmerge document depending on a value in the next record

The Situation
I maintain a legacy MS-Access database which is used to manage the contacts to a set of doctors offices. Initially the table "offices" (old) included information about the office and the employed doctors like this (abbreviated):
office
street
number
postcode
city
name1
surname1
name2
surname2
name3
surname3
An office could have between 1 and 3 doctors.
Initial Steps
A new requirement came up which asked for the separate modelling of offices and doctors as a 1:n Relationship.
I created a new table doctors:
name
surname
office_id
transformed the underlying data, dropped the redundant fields from the "office"-table and am now in the process of modifying the buisness logic accordingly.
First idea: Elegant or lazy? It fails any way
My first impulse was to create an "office" view which recreated the old "office" table and change the references to the "old" office table to this "office" view. This way I could keep the logic as it is and only adjust as needed.
The problem was, that the "office" table is very fundamental and used all over the place and i didn't manage to recreate the table without writing my own functions using a cursor making the view very costly. That the database is used in a Network environment didn't help because although this worked in principle, the .accdb file blows up to 70 to 80mb resulting in massive load times, making it in effect unusable.
Lets do it properly
So I ditched the "office" view and reworked the database to employ the new data model. A MailMerge Letter is given me particular trouble and i haven't found a good solution yet. The DataSource for the MailMergeDocument is a View relying basicly on the data in the "offices" and "doctors" table.
The issue
previously the Address field in word just used this as a datasource
id
street
postcode
city
name1
surname1
name2
surname2
name3
surnname3
3
Mainstreet
01234
timbuktu
Doe
John
Mae
Jane
Bar
Foo
Now i have an 1:n relationship and the datasource looks like this:
office_id
street
postcode
city
surname
name
3
Mainstreet
01234
timbuktu
John
Doe
3
Mainstreet
01234
timbuktu
Jane
Mae
3
Mainstreet
01234
timbuktu
Foo
Bar
However i still need to get all 3 (or in other cases just 2 or 1) Doctors on the adress field and yes there can be more than 1 office listed in the datasource.
Possible Solutions
I see basicly 2 Options:
Transform the view back into the previous format, without using Custom Functions, making it costly again, using a Single SQL-Statement.
Using the field functions within the word document to skip through the records as needed.
In theory the Nextif-function should do exactly that, however i haven't been able to figure out how and if I can evaluate Data between different records in the word document. I need something like:
Nextif nextrecord.id = currentrecord.id
but i havent found a way to reference the records whithin the fieldfunctions.
Any suggestions for a clean solution are welcome.
Regards
As is so often the way, after spending all this time posing my question, i have found a way to tackle the problem. I thought about solution 1 recreating the old table format without the use of VBA and came up with a lean way to do it.
The idea
If my doctors where numbered per office like this is doc no 1 in office no 6 etc i could simply count to three in the office table and refer to this unique DocID in a Join.
I need a view based on the office table that looks like this:
office_id
docid1
docid2
docid3
street
postcode
city
6
61
62
63
..
..
..
and a view based on the doctors table looking like this:
doctor_id
office_id
doc_id
name
surname
72
6
61
..
..
73
6
62
..
..
74
6
63
..
..
office view
This one is easy enough we take the office table as the basis for the view and simply add the following colums:
[office.id]*10+1 AS DocID1, [office.id]*10+2 AS DocID2, [office.id]*10+3 AS DocID3
doctors view
this one required a bit of googling but i found this forum post (#June7 is that also you in that thread?)
so we take the doctors table as the basis and add the following column:
[Office_ID]*10+DCount("1","Doctors","office_ID= " & [Office_ID] & " AND Doctors.ID <= " & [Doctors.ID]) AS DocID
This gives us the desired Doc ID and we can now create a third view based on these 2 where we add the doctors view 3 times and join it each time with docID1, docID2, docID3 respectively and each time add name and surname.
conclusion
It is possible to recreate the old table without using VBA and solely relying on built in functions and SQL. I expect this to be a reasonable fast way to achieve this although i haven't measured it.
I welcome comments and improvements but I am now reasonably happy with the result.
Thanks for your input.
For your original layout, the possibility of more than one entry could have been handled seamlessly via standard field coding in the mailmerge main document. For example:
Dear Dr {MERGEFIELD name1 \f " "}{MERGEFIELD surname1}{IF{MERGEFIELD surname2}<> "" "¶
"}{MERGEFIELD name2 \f " "}{MERGEFIELD surname2}{IF{MERGEFIELD surname3}<> "" "¶
"}{MERGEFIELD name3 \f " "}{MERGEFIELD surname3}¶
{MERGEFIELD office} {MERGEFIELD number} {MERGEFIELD street}¶
{MERGEFIELD city} {MERGEFIELD postcode}
For your 1:n relationship layout, you could save yourself a lot of effort and use Word's DATABASE field in conjunction with your mailmerge. For example, assuming you have a table of office_ids, with the addresses in that table:
Dear Dr {DATABASE \d "Filepath/MyDatabase.accdb" \s " SELECT [Name]&' '&[Surname] AS `Addressee` FROM [Doctors$] WHERE [office_id] = {MERGEFIELD ID}"}¶
{MERGEFIELD office} {MERGEFIELD number} {MERGEFIELD street}¶
{MERGEFIELD city} {MERGEFIELD postcode}
Note: The field brace pairs (i.e. '{ }') for the above examples are all created in the mailmerge main document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from here. Nor is it practicable (for the most part) to add them via the standard Word dialogues. The spaces shown in the field constructions are all required. Instead of the ¶ symbols shown in the examples, you should use real line/paragraph breaks.
For more details, plus links to practical examples, see:
https://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html
https://www.msofficeforums.com/mail-merge/38721-microsoft-word-catalogue-directory-mailmerge-tutorial.html

Create a list from Table

I managed to enter data to a database via a form;
actually works like a charm.
Now, what I need, is a lookup function (preferably not a form), with which I can search a table on another worksheet.
Let's say, I have an edit field or a cell, in which I enter a term which shall be looked for in a certain column on the table in another worksheet.
I would like to get a list of all entries which contain the word and the value from another cell (an ID).
Example:
Search term: Tom
Table:
Tim | 2
Tom | 3
Tommy | 5
The List should Show Tom and Tommy and their respective IDs,
but everything I tried didn't turn out as intended (mostly didn't work at all)...

SSRS Lookup on single dataset

Hopefully you can help!
I have a single data source in my SSRS report. With this data source, I have populated a tablix. The tablix looks something like this:
SalesPerson ID Group Sales
Sarah 1 1 1234
Ross 2 1 555
Gemma 3 2 678
Jill 4 2 345
Jack 5 3 987
Peter 6 2 432
Henry 7 2 356
The report is set up to create a different page for each of the sales people. for example, on the first page of the report, only first record would be shown (the record that holds Sarah's information, the second page would show the record for Ross' information ,etc..)
The issues I face is this:
At the bottom of the report, I need to include a textbox that displays the group number that the specific employee belongs to (the employee who is currently being displayed on the page).
I think that I need to do some sort of lookup on the IDReportItem to return the group ID in order to do this, but have had no luck in my attempts.
I understand that this is a horrible way of doing things, but I am limited to using this single dataset for performing this task.
Any help you can provide will be greatly appreciated,
Thanks you!
Unfortunately there doesn't seem to be a way to do this in a single textbox, but you can do it with a second tablix that uses the same dataset.
Create your second tablix and position it at the bottom of the page, then set your grouping to be the same on both tablixes and use the second tablix to only display the group ID, plus whatever label you want.
Create a new row group for each tablix (grouping on group ID), then right click the group and browse to Group Properties -> Page Breaks and check the box that says "Between each instance of a group". Do this for both tablixes.
This is what grouping is designed for. Build your table, and set the page break attribute to true.
You can have multiple rows under your group. Since your group is a field, simply add it to the detail row.
Your grouping is obviously set up right to get the report paging correctly.
You could add a List to the report, set the grouping on that (with page break between groups)
Inside the list - Add a RECTANGLE. (this be important!)
Once you've added the rectangle, you can add another as many objects as you like. In your case I think that may be a matrix and a text box
eg
Then it just becomes as spacing issue (to get the page looking right)

Display only two fields from Access table

New to Access here... I asked a similar question the other day, but have a new twist for a different form I am creating.
Say I have a table (tblNamesAndValues) that looks like this:
Name Value
---- ----
Mary 100
Carrie 500
Terri 999
Gerrie 749
I have created a form that displays all four names and values.
My question is this: how can you make the form display only the names Mary and Terri and their values, and have the values in updateable textboxes? On top of that, is there any way to only display those two, and not the blanks underneath that allow new entries?
Thanks in advance...
You can filter the form or use a query instead of the table as table source:
select * from tblNamesAndValues where name = "Mary" or name = "Terry"
For disabling the blank line, just set the AllowAdditions property of the form to false.

Create a Parent–Children Web Part Page

I am trying to figure out how to do something that I would think is commonplace, but I cannot find how to do.
Given two Custom Lists, one with a field that is essentially a primary key, and the other with what is essentially a foreign key, I want to show all the rows from the first in one area of the display, and the related records for the selected row of the first, in a second part of the screen.
I am thinking this would be side–by–side web parts on a web-part page.
So:
ID pkID Data ID fkID Data
___________________ ______________________________
| 1 100 Row one. | | 8 100 Related one/one |
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ | 9 100 Related one/two |
2 113 Row two. | 10 100 Related one/three |
3 118 Row n. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
11 113 Related two/one
12 113 Related two/two
13 118 Related n/one
(That is my attempt to show what is established between the two lists. Top row selected on the left, related records from the other row on the right.)
Surely this is common enough that there is a way to readily do this?
I suppose I might need to create a means of asserting that a row is 'selected.'
You will note that I am not useing the ID field that "belongs" to SharePoint.
You can create look up fields to establish that relationship, sharepoint 2010 even allows you to enforce the relationship like in a SQL database. so for instace you can declare what happens if you try to delete a parent if there is childs (Cascade, Prevent, etc).
Have a read here:
http://office.microsoft.com/en-au/sharepoint-server-help/create-list-relationships-by-using-unique-and-lookup-columns-HA101729901.aspx
About visually displaying them, you might have to create some webparts for it, as the only support OOB is the link to the child entity from the main entity on the parent list.