Bound combo box in form does not always update table - database

I'm struggling with a problem which I can't work out is due to a logical error, a design error or both. Or maybe it's something else entirely.
I have created a simple customer services database and form based user-interface for my company. When a user answers the phone they are supposed to log the call in the system if it is an issue relating to a product.
Sometimes a chain of stores which we have a special relationship with calls up on behalf of customers and we take their reference number and give them ours. This system actually works pretty well if I may say so myself (!), but I noticed after a while that when this store calls up and gives us their number, when they are logged into the system their branch number/name is not updated in the table record.
Here is a summarised outline of the relevant database tables. I renamed the store to SpecialStore:
Issues
IssueReference
ProductID
CustomerID
SpecialStoreBranch
Customers
...
Products
...
SpecialStore
SS_ID
City
Address
The idea is that even if it is either a customer or the store with their own IDs, the products are still stored in the same Products table, just with either the CustomerID or SS_ID filled in. Then when issues are logged, the store or customer is set and logged against a product.
In my main form I have a variety of boxes for a new issue to be filled in. There are combo boxes to select the CustomerID, ProductID etc, and of course the SpecialStoreBranch. These are all bound to the table, and the combo boxes all have row sources relating to their particular table. E.g. CustomerID combo box is a list of the IDs in the Customers table. (This is filtered to the required one elsewhere in the form.)
The Issues table SpecialStoreBranch field has the following query as its Row Source:
SELECT SpecialStore.[SS_ID], [SpecialStore].[City] FROM SpecialStore;
This is the same row source for the combo box on my main form.
The Column Count is 2, with the Bound Column as 0 and the column widths, if necessary, are 1cm;2.544cm.
My main form combo box SpecialStoreBranch has the other attributes:
Limit to List = yes
Allow Value List Edits = no
Inherit Value List = yes
Show Only Row Source Values = no
On the form the CustomerID and ProductID store correctly when the record is saved, and they are also from combo boxes. The form refreshes to update those fields when another part of the form (adding new customers and products) is changed. Could this be why the SpecialStoreBranch does not update? What am I missing? Is there a way to test this? I have been trying to run user tests to see if it ever works, but all I know is that it doesn't always set. If I have forgotten a piece of information let me know.
Edit:
Looking here: BoundColumn-Propery, I'm not sure if setting the bound column to 0 is doing what I think it's doing. But even then it should still use that id number to input into the table I would have thought and if they are all the same, what does it matter. When I tried setting it to 1, it took the text value in the table. Confusing!

Related

Problem with Showing Query Results on a Form

I'm having a Projects lists Continuous form where the form's Record Source is based upon a table.
I have a requirement to display a field from another table which is linked back to original table using its primary key. The primary key is a AutoNumber field, but when displaying in the form I've used Input mask something like this "TMG/FEA/"0000.
So I made:
a unbound list box
and made the Row source as the query which displays the relevant information from second table
This query was created using primary key displayed in form (I mean the [Forms]![Form Name].[Field] ) as the where clause.
But the results returns blank. I'm Stuck here. I'm not sure if the query is not working due to the Input Mask or because of something else. Please help me. Thanks in advance
You should add to form field listbox, and set following values:
Data: primary key of your first table
After this, that field will duplicate ID value. Now you should transform RecordSource of this field in order to see contents from second table. So you should set:
SELECT [PrimaryForeignKeyID], [DetailedField] FROM tblSecond;. Actually I don't know the contents of your second table. Whereas PrimaryForeignKeyID is a field that links second table to first, so-called FK.
After this set following properties of list box:
ColumnCount = 2
ColumnWidth = 0;2
AllowEdits = False
Save form and open it for viewing.
In this case, your listbox will show the associated contents of second table on form.
So to my mind it is better for you to do such simple tables and forms, and you'll realize idea.

SQL Server Reporting Services 2005 how to create nested groups

I know it's old technology (ancient now), but it's what I have to work with due to work.
I am able to create a Group and report and link it to a textbox to provide a collapsible report, with master data and detail data.
What I want to know, is it possible in SSRS2005 to create another sub-group to the first group?
i.e. Master record -> Detail -> Sub-details
Every time I try and add another detail row for example I only get one row of data in the sub-group, because it's tied to the Details Grouping. I cannot explicitly say "report grouped by this other subgroup" (where it offers you to create groups in the Group list).
Yes I am trying to do this in a table.
This is what I am after...
[+] Col1 Col2 Col3 Col4
[+] data data data data
Col1 Col2 Col3 ...
data data data ...
...
...
The [+] is what I want to set up to allow the expansion of another group within the first group.
The answer is not to try and pack too much into one reporting object. In this case the Table object.
I managed to have far more flexibility by placing the tables and fields inside a List object.
Try these...
Drop a List item into the report
Define the Dataset to your main dataset that contains all the data.
Note: For this to work you need a query that have as much as the master and detail data inside as ONE query, so obviously your master data will repeat as deep as it has to, to get to the lowest common dataset, which in my case was the action items per student.
The List object will act as the Master data reference for all your other objects inside of it.
Now you can play! Drop in a few textboxes to show the data for the master data you want to only show ONCE per "logical record". I'll let you ponder what that meant!
Now to show subgroups, you'll need Tables for each one. Drop a Table object
In each table (group) don't specify a dataset, as I said above, all the data comes from the List.
But for each table, you'll need to define your Details Grouping. Go ahead and simply state the group parameters you require for the sub-group. So in my case, I want to display ONE row of Students, but any amount of Actions each student has. So place a StudentID for the student and an ActionID for the actions as a combined grouping.
Repeat the above for any other groups, and define their groupings so you don't get repeatitive data. One table could only have one pivot or group, so just define the index for that inside the Details Grouping. Do not use the Add.. feature to add groups, because you'll be adding groups within subgroups and go into another level again! Beware.
I hope this made sense.

Look up information in onetable to populate values in a form bounded to another table

I have an excel sheet with information about each employee. I keep getting new updated spreadsheet every month. I have to create a database managing cases related to the employees. I have a database and the bounded form already created for the cases which also contain emp info fields. What I am trying to do is to only type in the emp id in the form and want the form to look up in the spreadsheet(which can be a table in the cases db) and populate other fields in the form and that information can go into the cases db. Can this be done?
Assuming the Employee information is available within the current database, perhaps in a linked (Excel), table there are a number of ways to approach this, one of which is:
Create a form based on the Employees table, showing the fields that you are interested in auto-populating
Delete the RecordSource of the form
Delete the ControlSource for each of the controls on the form. You need to do this otherwise they will all initially display with the error #Name?
Set the Locked or Enabled property of these controls to Yes or No respectively, so that the information they will display will not be editable
Add a, for example, Combo Box to the form; you can accept the third option in the Controls Wizard to help you populate this. You need the EmployeedID as the first column, but can add additional columns
Delete the Embedded Macro that Access creates (or Macro for Access 2003 or earlier) for the AfterUpdate event
Click the build button for this event (...) and create some code.
Here is some code I used with my sample Staff Database:
Private Sub cboStaff_AfterUpdate()
Me.RecordSource = "SELECT StaffID, Title, FirstName, Surname FROM " _
& "tblStaff WHERE StaffID = " & Me.cboStaff
With Me
.txtStaffID.ControlSource = "StaffID"
.txtTitle.ControlSource = "Title"
.txtFirstName.ControlSource = "FirstName"
.txtSurname.ControlSource = "Surname"
End With
End Sub
Whenever the user selects a staff (or employee) member from the combobox this will retrieve the data from the table and populate the various controls on the form. These controls will not be editable as they will be locked or not-enabled. (You can also set the Allow Additions and Allow Deletions properties of the form to No, but Allow Edits needs to remain as Yes, otherwise the combobox won't work.)
This code can be improved. In particular, to only set the RecordSource and ControlSource s once.
Obviously I am not aware of the specifics of your database, and there are other ways to approach this.
Added If, however, the RecordSource for the form is some other table that you are hoping to populate with some details from the Employees table then, instead of changing the RecordSource and ControlSource as indicated, you could use ADO (in the AfterUpdate event of the combobox) to create a RecordSet containing a single row (the chosen employee's details) and set the values (the Text) of controls on the form to the values from this recordset. As I say, there are a number of ways to approach this.
Added In response to:
"The changes you requested to the table were not successful because
they would create duplicate values in the index, primary key or
relationship...."
I don't know your precise set-up but I can tell you why this is happening. The default behaviour in Access is that, for a bound form, if a change is made to any one of the bound fields, then an attempt to navigate away from the record will cause Access to save the record.
Is the form bound when it doesn't need to be? Or have you set the ControlSource of a control to a field when it doesn't need to be? If this is not the case then:
In the BeforeUpdate event of the form you can set the Cancel argument to True to prevent the update (or insert). However, this will prevent ANY new record from being inserted. You can either have a Button that the user needs to click to explicitly save the record, or, in the BeforeUpdate event, test some condition with If to decide whether you will allow the insert (or update) or to stop the record from being saved (by setting Cancel = True).

filter data from one table based on second table without duplicates

Note: I'm working with a large complex database, so for clarity's sake I have simplified the set up below.
I struggled a bit with how to title the question since it's a bit of a complex question. I hope it's accurate enough....
A bit of background first:
I have an Access 2010 database that contains a one-to-many relationship between a table Called "Products" and a table called "Datasets" (ie I have a bunch of products, and each product has multiple datasets). Each has an autonumber key field (p_ID and d_ID respectively) as well as numerous other fields.
I have a form (lets call it frm_Main) that has two subforms: sub_Products (based on the "Products" table) and sub_Datasets (based on the "Datasets" table). On the main form I have a control ctrl_SelectedProduct which is linked to [sub_Products]![p_ID] to see which record in sub_Products is selected / has the focus, and the sub_Datasets subform is linked to this control so that it only displays Datasets records that belong to the selected Products record.
On the main form I also have a number of controls that I'm using for filtering the data in the subforms. For example, I have a control ctrl_Category. I have this control coded so that when the user changes the value of the control, a filter is applied that limits the records in sub_Products to only those that have a p_Category value equal to whatever is chosen in ctrl_Category. If the control is blank, it will show all records. All this works great when if comes to filtering based on fields in the Products table.
Now the problem:
My problem is that I also want to be able to filter based on fields in the Datasets table. For example, Datasets has a field called d_Status. I want the user to be able to chose the status in a control (ctrl_Status), and based on this:
1) sub_Products will be filtered to display only those Products records that have an assotiated Datasets record (or records) that has d_Status equal to whatever was chosen in ctrl_Status
then
2) when a Products record is selected in this filtered sub_Products, sub_Datasets will only show the Datasets records that has d_Status equal to whatever was chosen in ctrl_Status
I know how to do part2. But I have no idea how to get part1 to work. Since sub_Products is currently based on the Products table, which does not have the d_Status field, I have no way to filter it based on that field. Thus, I'm assuming my first step will be to change my setup so that sub_Products is based on a query that combines the two tables (or at least adds the d_Status field).
If I do that, however, I get duplicate Product records. I can't use the query's Unique Values property because if I have a product that has two datasets, one with status "Current" and a one with status "Archived", then those aren't considered duplicates, and the product info is there twice. If I don't have the status field displayed, it shows only unique products initially, but then I can't subsequently apply a filter based on that non-displayed field.
I also tried basing sub_Products on a Totals query in order to utilize the Group By functionality, but I still couldn't get it to work right. Even if I could I don't think that's the best solution, because you can only have 10 fields with Group By, and my Products table has more than 10 fields that I need displayed in sub_Products.
I feel like I'm now just going around in circles and am at a loss of what to try from here. Please help!
Couldn't you add something like this?
Private Sub ctrl_Category_AfterUpdate()
Form_frm_Main.Recordsource = "Select * from Products where p_ID IN(" & _
"Select p_ID from Datasets where d_Status = " & _
Me!ctrl_Category.Value & ")"
End Sub
Alternately, you can access the childform via the parent of the other child form.
This is a non-working snippet just to give you the idea:
Me.Parent.otherChildFormName.Form.Recordsource = whatever

Auto filling a field in access 2003 with data from another table

I have an access 2003 database with many tables. Here is an example of what i am trying to achieve. I have a table and form for my candidates. On this table is a field for name and a field for an enrolment number. Is it possible for my other form to fill in the enrolment number on that form automatically when the same name is selected. For example, if I have a candidate on my candidates table with an enrolment number filled in. If I select that candidate on my other form how can I make it automatically fill in the enrolment number. Hope this is clear enough.
Any help would be greatly appreciated. Thanks.
There are several ways to do this.
If you are using a combo box to select the candidate from the candidates table, the enrollment number can be one of the columns, in which case you can simply refer to the column in the controlsource of a textbox:
=MyCombo.Column(2)
Similarly, you can use DLookUp, but it can be comparatively slow if your tables are large:
=DlookUp("enrollmentnumber","candidates","UniqueNumericID=" UniqueNumericID)
Where UniqueNumericID is a control or field (column) in the form or the form's recordset.
It may also be possible to create a query that holds all the relevant data and use that for your form's recordsource. This is quite a nice solution, usually, for example:
SELECT This, That, Candidates.EnrollmentNumber
FROM ExamsJunctionTable
INNER JOIN Candidates
ON ExamsJunctionTable.CandidateID = Candidates.UniqueCandidateID
For this to work properly you need to ensure that you database is well set-up and that the queries that need to be updatable are updatable.

Resources