ComboBox Access Match on ID but Display Category - ms-access

I am working on a project but have run into a wall with Access's combo-boxes. I've attached an image so things (hopefully) make more sense when I describe my situation.
I have two combo-boxes on a form, the left one is called cmb_body_system, and the right one is called cmb_icd9code.
What I am trying to do is have the left box display three options, the three from the body_system_type table: infectious, circulatory, respiratory. From there, the second box will display the matching description in the ICDLight table column titled icd9Description.
I have gotten as far as getting the left box to display the bodyID's associated with each matching Icd9Description, but I can't get further than that. The VBA that I have on these is:
Private Sub cmb_body_system_AfterUpdate()
cmb_icd9code.RowSource = "SELECT ICD9Description FROM ICDLight WHERE ICDLight.bodyID = " & Me.cmb_body_system & ";"
End Sub
And as you can see, it's working, but I want to go that one step further and don't know what/how to search for this exactly. I mean, I don't even know how inaccurate/accurate the title is for that matter.

I think you need to rephrase your question. From your question title, I think this is what you need.
Select your cmb_body_system
Go to property sheet
Under Format tab:
Column Count = 2
Column Widths = 0cm; <- there is a semicolon
Under the Data Tab
Bound Column = 1
Row Source Type = Table/Query
Row Source = "SELECT * FROM BODY_SYSTEM_TYPES"
Now your combobox will show "bodysystem" as display text and Bodyid as value

Related

SSRS report tables mutiple lines not showing

I am doing Microsoft Dynmics D365 report layout. I have a table in my report that need to show the lines from the table in MS Dynamic D365. Which have only 2 lines.
D365 frontend system:
In the report layout, it is only showing the first line and the second line is not showing.
Report layout first line only showing:
I want the 2 lines to be showed in the report. I am not sure if my coding is not right or the row group that I am grouping in the report design. Please help me please. Apperciated.
here is my code in the dp class to get the table lines:
PurchPurchaseOrderTmp.MGAItemLabelName = PurchExtendedMaster.ExtName;
PurchPurchaseOrderTmp.MGAColValue1 = PurchExtended.ColValue1;
PurchPurchaseOrderTmp.MGAColValue2 = PurchExtended.ColValue2;
PurchPurchaseOrderTmp.MGAColValue3 = PurchExtended.ColValue3;
PurchPurchaseOrderTmp.MGAColValue4 = PurchExtended.ColValue4;
PurchPurchaseOrderTmp.MGALabelId = PurchExtended.LabelId;
//PurchPurchaseOrderTmp.MGALabelIdString += int2Str(PurchExtended.LabelVersion);
if (PurchPurchaseOrderTmp.MGAItemLabelName != "") {
PurchPurchaseOrderTmp.MGALabelIdString = strFmt("%1-%2",
PurchExtended.LabelId, int2Str(PurchExtended.LabelVersion));
}
else {
PurchPurchaseOrderTmp.MGALabelIdString = "";
}
Here is my report design row grouping:
Thanks
This is not really an answer at the moment as I can't see enough to be certain but...
Looking at the report design, it 'appears' that you don't have anything in the details row(s). The details group rows have been reduced in height so I'm guessing there is nothing in there.
That means that the text boxes below this must be in a group header or footer which is why they will only appear once.
The best way to get your head round this is to dump all the data from your dataset into a simple flat table, then see what you want repeating.
For exmaple, it looks like Label ID (MGAItemLabelName ?) should only be shown once, so there needs to be a group for that - which it looks like you have.
Then within that label name group, you have two rows of data that you want to show, so these must be at a lower level than their parent group. That might be the details row group, or another row group between the header and details depending on your needs.
The details row group typically contains fields that you want to show every instance of and that does not have any subordinate/child data.

Having a report display everything from a form

So I have a combo box on my form, and depending on what is selected, the query filters the info and runs the report and displays that info. What I would like to do is have the report display everything when the combo box is left blank. Is there any way to do this?
Posting sample code would help, but here is a general answer.
I assume your query filter looks something like this:
SELECT Stuff From Table Where MyField = MyComboBox
If that is the case, you can do the following:
SELECT Stuff From Table Where (MyField = MyComboBox) OR NZ(MyComboBox, "") = ""
If either your combo box us set to nothing or an empty string, you will get the full result.

Autofilling my form in Access with the use of a Combo Box

I'm having a problem when I want to autofill my form in Microsoft Access. The idea is that I use a combo box to select a name. Then the onChange code of my Combobox automaticlly inserts all the other data in the proper field. I use this code on the Combo Box.
Private Sub cmbName_Change()
Me.tbPersonalNumber = Me.cmbName.Column(0)
Me.tbEmailadress = Me.cmbName.Column(2)
Me.tbBirthday = Me.cmbName.Column(3)
End Sub
This methode works fine for the personalnumber and the emailadress. But it doesn't work for the birthday date, it returns a null value but when I check my table there is is a date in the proper field.
Am I missing something? I tried everything but it wont work.
I was thinking that the problem is related to the birthday column being the last in the table. Or having the date type.
Thank you in advance for your time and efford!
Edit; The .Column(1) is missing because this is the name that is already inserted with the ComboBox.
There is some confusion caused by the wording of the question, I'll try to state back how I've interpreted and if I have it right it may lead you to an answer.
You have combo box called cmdName that is pre-populated with data from a table. The content of the combo box could look as below (you may have set column widths to zero to hide the data)
0001|Gary Evans|gary#email.com|01/Jan/1970
0002|J Rommers |JR#email.com |02/Jan/1970
When the user selects J Rommers Me.tbPersonalNumber is populated with Me.cmbName.Column(0) (0002) and Me.tbEmailadress is populated with Me.cmbName.Column(2) (JR#email.com) but Me.tbBirthday is not being populated with Me.cmbName.Column(3) (02/Jan/1970).
Assuming Me.tbBirthday is a text box with no code that might clear it out, I suspect the issue is within the combo box. Not being sure how your combo box is set up, I would suggets the following checks:-
In the combo box properties, does the Column Count equal 4?
In debug, with a breakpoint on Me.tbBirthday = Me.cmbName.Column(3), does it show you the date you are after?
If it is not there does the query that populates the combo box have it in?
Edit based on comments to help further: -
Change the query to SELECT Personel.PersonalNumber, Personel.Emailadress, Personel.Birthday, Personel.Name FROM Personel ORDER BY Personel.Name; this puts all the fields you want hidden at the front.
Change the column widths property of cmbName to 0,0,0, this first the ones you want hidden and leave the last one to fill the width of the combo box.
Ensure the column count property is still 4 as per the answer
Change your code as per below and Gustav's answer
Replacement code:-
Me.tbPersonalNumber = Me.cmbName.Column(0)
Me.tbEmailadress = Me.cmbName.Column(1)
Me.tbBirthday = DateValue(Me.cmbName.Column(2))
This accounts for the fields moving in the query and ensure the date shows as a date like you wanted.
Comboboxes (and Listboxes) always return a string, so convert that to a Date value:
Me!tbBirthday.Value = DateValue(Me!cmbName.Column(3))

Referencing list boxes in Access

I'm new to Access so this might be a simple question.
I have a form in Access 2013. There is a subform displaying a table from an SQL server, like so.
Company Product
-----------------
CompanyA Product1
CompanyA Product2
CompanyB Product1
CompanyB Product2
Using ListIndex in a list box, I can display the index of any row I click on. For example if I click on the second row (CompanyA, Product2) the list box shows a ListIndex of 1. If I click on the third row the ListIndex is 2.
How do I get a list box to display the value of a column instead of the ListIndex?
What I am trying to do is that, when I click on a row in the subform, I'd like to display each column value for that row in its own list box.
However, I cannot seem to use ListIndex as a variable in a larger function. I've attempted the following:
Typing only the column name into the list box. Does not update the value if I click on a different row.
Column property does not update the value if I click on a different row.
Controls property gives an error.
Value property displays the correct row but only works for the first column.
Combo boxes circle back to the problem that I need to use ListIndex as a variable.
Is there a different property I should be using? Am I missing something in the properties I tried?
There seems to be a little confusion with terminology. Your List3 is a list box, not a subform.
The fields Company and Product look like text boxes, but if the first one has the control source =[List3].[ListIndex], and shows a text and not a number, it seems to be a listbox with height = one line.
I suggest using text boxes for Company and Product, with these control sources:
=[List3]
for the bound column. Alternatively, for consistency: =[List3].Column(0)
=[List3].Column(1)
for the second column.
These text boxes update themselves automatically when you click on an item in the listbox.
To get the value of a listbox, and if you allow multi-select, use the following example:
For Each varItem In Me.lstHierarchy.ItemsSelected ' Loop through the items selected (if multi-select allowed)
strPrint = ""
For i = 0 To iCols ' Loop thru each column in a row
strPrint = strPrint & "|" & Me.lstHierarchy.Column(i, varItem)
Next i
Debug.Print "Selected Value: " & strPrint ' Display the row; columns are delimited with '|'
Next

combobox cascade effect not working for different rows

I have two comboboxes on a subform.The first combobox is used to populate the second combobox. These are placed in the detail section of the form. I want them to work this way:when I select any value from the first combobox, I want the second combobox of the same row to get populated by relevant value.
As of now, I have tried to implement this and as I select any value from the first combobox of row 1 I see the second combobox of the same row gets populated but as I go on selecting values from the first set of comboboxes I see that the values in the second set of the comboboxes above changing or becoming null.
Here's the code:
The 1st combobox is cboRCMTask:
Private Sub cboRCMTask_AfterUpdate()
Me.cboRCMTaskOptions.RowSource = "SELECT ID, RCMTaskOptions FROM tblRCMTaskOptions WHERE RCM_ID=" & Me.cboRCMTask.Column(0) & ";"
Me.cboRCMTaskOptions = Me.cboRCMTaskOptions.ItemData(0)
Me.cboRCMTaskOptions.Requery
End Sub
cboRCMTaskOptions is the second combobox.
The form_current event:
Private Sub Form_Current()
Me.cboRCMTask.RowSource = "SELECT ID, RCMTask FROM tblRCMTask;"
If IsNull(txtRCM_ID) Then
Me.cboRCMTask = Me.cboRCMTask.ItemData(0)
End If
Me.cboRCMTaskOptions.RowSource = "SELECT ID, RCMTaskOptions FROM tblRCMTaskOptions WHERE RCM_ID=" & Me.cboRCMTask.Column(0) & ";"
If IsNull(txtRCMOption_ID) Then
Me.cboRCMTaskOptions = Me.cboRCMTaskOptions.ItemData(0)
End If
End Sub
From your description, you are using a continuous form. While it looks like a continuous form has many rows, from the point of view of coding you can consider it to have just one row, the current row. I suspect that the control source for combo 2 is a hidden, numeric column in the combo, when you change the row source for the combo, the visible row can no longer be found, so it cannot be displayed. You will either have to provide a pop-up form for editing, or a textbox to store the value for the form and a slightly dodgy combo to edit that value. You can do a little to improve the appearance with conditional formatting.
in your first piece of code, shift the code to the on_click event. I am not sure what you are trying to achieve with the reference to ItemData but I think it is unnecessary, comment out that line.
Similarly the third to last line in the Form_current event, replace with a requery.