Multiple address rows with state list based on country - ms-access

I have multiple address rows with a state and country combo box. I limit the state list based on the country. It looks like
However, when I change the value of the state and this detail row loses focus, it saves and clears the value of the other state like
I have an event on the state field to set the list when it gets focus.
Private Sub cboState_GotFocus()
MsgBox ("Country: " & Me.cboCountry.value)
If Nz(Me.cboCountry, 0) = 0 Then
MsgBox "Please select a country first"
Me.cboCountry.SetFocus
Else
If Nz(Me.cboCountry.value, 0) = 0 Then
Me.cboState.RowSource = ""
Else
Me.cboState.RowSource = "SELECT id, stateCode, stateName FROM state where country_id = " & Me.cboCountry.value
End If
End If
End Sub
I tried setting 'Limit to List' to No, but it gave an error
I tried setting Column Widths to 0.001";0.3938";1.1806", but then it displayed the id field instead of the state code. Here are the current values
Column Count 3
Column Widths 0";0.3938";1.1806"
Row Source SELECT id, stateCode, stateName FROM state where country_id = [country_id]
Bound Column 1
Limit to List Yes
How can I have multiple state combo boxes, each with a different restricted list based on the country?

An Access combobox whose LimitToList property is set to Yes can only show values returned by the RowSource property, even if the ControlSource is set to another value.
The workaround is to put a textbox on top of the combobox (but not covering the arrow) and show the text value in the textbox, using =Dlookup("textvalue","tbl","Id = " & numericvalue) in the ControlSource property. That way you can show a value that is not in the list.

Related

MS Access: ComboBox Requery

I have a ComboBox which will display data which dependent on what has been entered in another ComboBox. The second ComboBox is not updating (showing) data in the dropdown after the first has been updated...
Company_Select_Combo is the first ComboBox. After a selection has been made in this combobox, Marketer_Select_Combo becomes visible on the form, and this query should reflect those marketers associated to the company selected in the first combo...
Help
Private Sub Company_Select_Combo_AfterUpdate()
If Company_Select_Combo > 0 Then
Company_Select_Combo.Enabled = False
Marketer_Select_Combo.Visible = True
Me.Marketer_Select_Combo.Requery
Else
Marketer_Select_Combo.Enabled = False
End If
End Sub
Let assume your "Marketer_Select_Combo" query includes:
Marketer_ID, Marketer_Name, and Company_ID
Then simply add the following statement to your SQL:
WHERE Company_ID = [Forms]![yourformname]![Company_Select_Combo]
This way, the elements should be limited to the chosen company. By calling the Requery/Recalc method as you did, it should work as intended.

How to refer to a specific textbox field in a specific record

I have a serch form and I want to be able to change value of text box field in a specific found record.
I have a combobox named Combo2 and a text box named TextBox1. I want to based on the selection in the combobox Combo2 change behaviour of the TextBox1. Problem that im suffering right now from is that selection of any record makes changes to all records not just the one I want.
Example: I look for a specific item and I get result that I have 5 items in Germany, 2 in England, 8 in Italy and 4 more in England. Now I want to move 2 items from England to Spain. When I select Spain in Combo box all TextBoxes in all records become inactive. I want only the textbox of record that I have changed to be inactiv.
Private Sub Combo2_AfterUpdate()
If Me.Combo2 = "England" Then
Me.TextBox1.Enabled = True
ElseIf Me.Combo2 = "Germany" Then
Me.TextBox1.Value = "Ger"
Me.TextBox1.Enabled = False
ElseIf Me.Combo2 = "Spain" Then
Me.TextBox1.Value = "S"
Me.TextBox1.Enabled = False
ElseIf Me.Combo2 = "Italy" Then
Me.TextBox1.Value = "I"
Me.TextBox1.Enabled = False
Else
Me.TextBox1.Enabled = False
End If
End Sub
That is by design. A control in a continuous form will behave and react the same on all records except for the Value property (which is bound to the record).
So you will have to rethink your concept and how to navigate the form and records.

To handle the increment and decrement of a value in an expression and display the corresponding indicator SSRS reporting service

I have a table table of values displayed in SSRS .
The table has fields metricID , currentmonth , preciousMonth
Questions :-
1. I have to compare 2 values like current month and previous month
Fields.PreviousMonth.Value < Fields.CurrentMonth.Value
THEn Check if the metric id is metricID is 7 then increase in currentmonth should be displayed as up arrow with red colour else it should be downarrow with green colour.
For all other Metric ID's it should be "upp arrow with green colour" else "down arrow with red colour"
Does anybody have an idea on how to do this
To do this you will need to set up custom indicators and set an appropriate expression to set the indicator.
I have some simple data:
And a simple report with an indicator per row:
The indicator is set up as:
Where the expression is:
=Switch(Fields!MetricID.Value = 7 and Fields!CurrentMonth.Value - Fields!PreviousMonth.Value > 0, 1
, Fields!MetricID.Value = 7, 2
, Fields!MetricID.Value <> 7 and Fields!CurrentMonth.Value - Fields!PreviousMonth.Value > 0, 3
, true, 4)
So what I'm doing is assigning each row a specified state based on your business rules, and I've set appropriate icons for each of those states.
Report is working as required:
You could move the expression above into a calculated field in the Dataset if you needed to use it in multiple places in the report.

MS Access runtime error 2115

In Ms Access, I have two unbound combo-boxes: StateBox and DVPCBox. StateBox is simply a list of U.S. states and DVPCBox contains Employee Names from a query based on the value of StateBox.
I'm trying to set the value of DVPCBox equal to the first item in its list. Since the list of Employees is based on the value of StateBox, I need the value of DVPCBox to update every time StateBox changes. I tried the following:
Private Sub StateBox_AfterUpdate()
Me.DVPCBox.Requery
If (Me.DVPCBox.ListCount = 1) Then
Me.DVPCBox.SetFocus
Me.DVPCBox.ListIndex = 0 //<-Error here
End If
End Sub
But I got runtime error 2115 - The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Office Access from saving the data in the field.
The strangest thing to me is that I'm not even using the BeforeUpdate Event or ValidationRule (as far as I'm aware.)
ItemData(0) is the first combo box value. So set the combo equal to that.
Private Sub StateBox_AfterUpdate()
Me.DVPCBox.Requery
If (Me.DVPCBox.ListCount >= 1) Then
Me.DVPCBox.SetFocus
'Me.DVPCBox.ListIndex = 0 //<-Error here
Me.DVPCBox = Me.DVPCBox.ItemData(0)
End If
End Sub
I also changed ListCount >= 1 because I assumed you wanted to do the same thing when the combo includes 2 or more rows.

List Box enable/disable one column

Access 2007: Is it possible to enable/disable one column in a List Box on a form. For example: Say you have 2 columns A,B - If Me.A = title Then Me.B.Enabled = True Else Me.B.Enabled = False.
If so, where would it go? On Got Focus, On Click??
Thanks
I'm not sure what you mean by disable, but you can hide a column by adjusting the ColumnWidth.
So if you wanted to hide column2:
Me.MyListBox.ColumnWidths = (1 in;0;1 in)
And to hide column1:
Me.MyListBox.ColumnWidths = (0;1 in;1 in)