I am working on this database in Access.
Here is how the table is:
in this table the conversion fromid and toid has to match that's why I have it structured like this. That is if I select MT, then I can only convert to another MT or ST. if I select ST in the base column then I can convert to another ST or MT.
I created this form below. it has 2 combo box. the second combo box is limited based on the selection from the first combo box. That is If I select MT in the first combo, then the only options available in the second combo box is MT or ST. If I select KG then combo box 2 is limited to another KG or LB.
but the problem is that, If I select one from the combo box 1, the matching pairs are not showing. that is if I select MT it doesn't limit to MT or ST, but show two other values like L and GLL.
I have attached a copy of the database.
Here is the link to the database I am testing with
Below is the snapshots of the code for each:
Your ID System with fromID to TOID does not seem to make any sense to me. First of all the pair is always the same. What is the intended benefit of this?
Alternative, just use the Text columns of Base and To instead and ajust properties of combo0:
Row Source: SELECT DISTINCT base FROM tblconversions;
Bound Column: 1
And the After Update method
Private Sub Combo0_afterUpdate()
Dim stoSource As String
stoSource = "SELECT DISTINCT tblconversions.To FROM tblconversions WHERE tblconversions.to = '" & Me.Combo0.Value & "'"
Me.Combo2.RowSource = stoSource
Me.Combo2.Requery
End Sub
Related
I have a query where the report name and report id are both displayed This only applies when the reports are pre-checked. The values are populated in a datagrid. If the report is unchecked, only the name is displayed. I tried using the UPDATE keyword but I kept running into syntax error. I know that the small change to the query is simple, but I am having a tricky time attempting to display the reportid when the report is unchecked or basically reportvisible being 0. How do I work around this to show the reportid regardless of if it is checked or not?
valsql1 = "SELECT c.ReportID, c.COMPANYID, rl.REPORTNAME
FROM CompanyReportListTable c
right join ReportList rl on c.reportid = rl.ReportID
and reportvisible = 1
and CompanyID =" & DropDownList1.SelectedValue & "
where rl.ReportID in (
Select ReportID
from ReportList
where ReportVisible = 1
)
order by ReportName"
You're right joining exclusively on reportvisible = 1, and then you're specifically selecting only reportIDs with reportvisible = 1. You are twice-over filtering out rows with reportvisible = 0, so of course you aren't going to get reportids for those rows. You should add rl.reportvisible to the SELECT clause and remove reportvisible = 1 from the join and where clauses.
It is only a one word/two letter change. At the first SELECT statement, instead of c.ReportID, it should be rl.REPORTID. Refer back to the right join; y using a right join, it returns the selected rows from reportlist, matches it with crl table. Now we made it so reportID appears regardless if it matches or not. Kind of like report name/title
I have a table named Persons such as :
ID Name
1 John
2 Jerry
3 Jack
I have set up a form named Form1 with a Combo Box named Combo1 .
Combo1 has 3 values-
1
2
3
All
Then I set up the following query:
Select * From Persons WHERE Persons.ID = (Forms![Form1]![Combo1]);
The query works fine when 1,2 or 3 are selected in the Combo Box but I can't figure out how to make it work to select all the records when the user selects 'All'.
I don't see why VBA is required. Seems to me you can get what you need with only a query ...
Select *
From Persons
WHERE
Persons.ID = Forms![Form1]![Combo1]
OR Forms![Form1]![Combo1] = 'All';
When All is selected in the combo box, the condition Forms![Form1]![Combo1] = 'All' will be True for all rows in the table. So none are excluded from the query's result set.
When anything other than All is selected in the combo box, the query will return only rows whose ID value matches the combo box value.
Not sure what your Combo1 looks like now?
Are you asking to show all entries with ID > 1 or all entries > than the ID selected in Combo1 - and do you still have the ALL option in Combo 1?
If you're just asking your last question:
How can I make it work so that the user can view All Names for ID's
greater than 1?
Then you can probably use
Select * From Persons WHERE Persons.ID > 1
AND (Persons.Name = Forms![Form1]![Combo2] OR Forms![Form1]![Combo2] = 'All');
But right now I think you have everyone confused with what you want. Hope I guessed right and put you on the correct path
My SSRS report (2008 version) has two parameters. The first is a textbox receiving input for Supervisor' userid. The second is a drop-down list which depends on the first parameter to show the all the staff name working under the supervisor. After I input a supervisor userid for the first parameter, the second one does not refresh automatically. Then I press enter for the first parameter, an error message shows I have to select a value for the second parameter. My questions is how the second parameter can refresh automatically after I input the first parameter in the textbox.
Thank you very much for your help!
Are both your parameters as well as the Network_ID all INTEGERS?
It might work better if your first parameter was also based on a drop-down based on another dataset.
SELECT DISTINCT a2.Last_Name + ', ' + a2.First_Name AS Manager_Name, a2.Network_ID as Manager_ID
FROM Client_All c
INNER JOIN DimStaff d ON c.STF_NBR = D.ECMS_Wrkr_ID
INNER JOIN STAFF s ON s.STF_NBR = D.ECMS_Wrkr_ID
INNER JOIN ADPFile a ON s.FILE_NBR = CAST(a.FILE_NBR AS nvarchar)
INNER JOIN ADPFile a2 ON a2.Position_NBR = a.Supervisor_Position_NBR
I am currently using a continuous form to a show a set of data that results in the following format (each line being one record):
1/04/13 Person1
31/03/13 Person1
30/03/13 Person1
29/03/13 Person2
28/03/13 Person1
There are 100s of these records and I would like to condense it to the following:
30/03/13 - 1/04/13 Person1
29/03/13 Person2
28/03/13 Person1
The data is from a query, so can be manipulated at the SQL level before it even gets to the form stage. I am also comfortable using macros or VBA to manipulate the form. However, I still haven't been able to find a suitable way of doing this.
I realise that this is typical behaviour for a report, but since I eventually want this to be embedded in another form as a subform, I can't use reports (can't create a subreport in a form unless I am missing something).
Any help or advice is much appreciated.
Good description of the problem. Try building your source query like this (assuming the fields are called MyDate and MyPerson and the source table is MyTable):
Select Person, min(MyDate) as StartDate, max(MyDate) as EndDate
from MyTable
group by Person
This gives you 3 fields that you can drop into your form.
Edit
Now that we have a more complete picture, the task just got more complicated, but you still have options assuming the 'events' between people don't overlap (if they do, then I can't think of how to create eventIDs afterward). In the absence of an EventID, you'll have to create one:
First, you need to move your data to a new table so that you can reorder it and add a blank field for the event ID you'll be adding in step 2.
1a. Copy MyTable into a new table. Add an extra field called EventID.
1b. To populate this table, first Delete * from TmpTbl
1c. Then something like:
Insert into TmpTbl.* from MyTable order by MyDate,MyPerson
This code will look through your temp table (TmpTbl as i call it) and add an event id.
Sub AddEventIDs()
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("TmpTbl")
Dim LastPerson As String
Dim EventID As Integer
docmd.setwarnings false
While rst.EOF = False
If LastPerson <> rst.Fields("MyPerson") Then EventID = EventID + 1
LastPerson = rst.Fields("MyPerson")
rst.Edit
rst.Fields("EventID") = EventID
rst.Update
rst.MoveNext
Wend
docmd.setwarnings true
End Sub
On the On Load event of your form, add in the 2 queries and the sub routine from #1 and #2.
Your final query will be:
Select MyPerson, EventID, min(MyDate) as StartDate, max(MyDate) as EndDate
from MyTable
group by MyPerson,EventID
I have a listbox with values. Now I need to sort that listbox, BUT NOT BY ALPHABETICALLY.
You see the values in a listbox are from a table.
------------------------
| name | order | size |
========================
value1 4
value2 3
value3 1
value4 2
I hope I made myself clear. So the list box has the items "value1, value2, value3, value4". I want it to sort by the order declared in the table. The list box has nothing to do with the table and is not "data bound" to it. The values come from somewhere else.
Tech used: VBA, Access 2007
It sounds like the Row Source Type for your list box is "Value List". Since the values come from a table, change Row Source Type to "Table/Query", then use a query for Row Source:
SELECT [name], [order]
FROM YourTable
ORDER BY [order];
You don't have to display [order] in the list box ... set its column width to zero.
Your list box control does not have to be bound to a data source field for this approach to work. If the list box is unbound, the user selection will not be stored, but the list box will still allow users to make selections from the list box.
Notice I enclosed [name] and [order] in square brackets because both are reserved words. See Problem names and reserved words in Access
Dim First As Integer
Dim Last As Integer
Dim a As Integer
Dim b As Integer
Dim Temp As String
Dim test() As String
First = LBound(test)
Last = UBound(test)
For a = First To Last - 1
For b = a + 1 To Last
If test(a) > test(b) Then
Temp = test(b)
test(b) = test(a)
test(a) = Temp
End If
Next b
Next a
For a = 1 To UBound(test)
lst_email.AddItem test(a) 'lst_email is a listbox
Next