After Me.Recalc in Access off-screen values are not displayed - ms-access

From VBA I'm setting a series of text boxes to have DSum controlSources:
Me.Oct.ControlSource = "=DSum('GBPValue', _
'MF YTD Actual Income & Adret', _
'Month=10 AND Org_Type=[Key]')"
Me.Nov.ControlSource = "=DSum('GBPValue', _
'MF YTD Actual Income & Adret', _
'Month=11 AND Org_Type=[Key]')"
and then running Me.Recalc to get the values to show up once set. This works fine for the text boxes that are on-screen when the form loads but for ones on the same (very wide) form that are not currently on screen the Recalc seems to do nothing. If I scroll across the form and select the blank fields the values then show up. Is there any way to get the values for every text box on-screen or off to be there on form load or, at worst, when the user scrolled across?

I can guess why this must be happening: it's likely that Recalc doesn't repaint controls that are not currently visible. So even though the value of the controls has in fact changed, their cached visual appearance still appears empty when the scrolling windows reveals them.
Here's what I'd recommend: create a member function on your form like this:
Function GetMonthValue(Month As Long) As Double
GetMonthValue = DSum("GBPValue", "MF YTD Actual Income & Adret", _
"Month=" & Month & " AND Org_Type=" & [Key])
End Function
The control source for the text boxes can then be set to "=GetMonthValue(1)" and so on. This means that each control's source is declared statically and there's no need to change anything when the form loads. When the current record changes, the value should track, although I haven't verified this with testing.

I don't know what the problem is but you can try this:
...
Me.Oct = DSum('GBPValue', _
'MF YTD Actual Income & Adret', _
'Month=10 AND Org_Type=[Key]')
Me.Nov = DSum('GBPValue', _
'MF YTD Actual Income & Adret', _
'Month=11 AND Org_Type=[Key]')
...
Set control's text by using DSum directly.
Edit: You can also try refreshing the form after the calculations, i.e. Me.Refresh.

Related

Problems Searching in Access

Wonder if any of y'all can help me. I keep getting errors on this. Here's my table:
- tblCutting
- PartNumber (Primary Key Text Field)
- CuttingStep1 (Number)
- CuttingStep2 (Number)
- CuttingStep3 (Number)
I'm trying to use a combo box (cmbPartNumber1) to pick from PartNumber and then a text box fills in with the corresponding CuttingStep1. Here's are the various formulas I've tried underneath the textbox:
=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [tblCutting]![PartNumber])
=DLookUp("CuttingStep1","tblCutting","[cmbPartNumber1]=" & [tblCutting]![PartNumber])
=DLookUp("CuttingStep1","tblCutting","cmbPartNumber1=" & [PartNumber])
=DLookUp("CuttingStep1","tblCutting","[tblCutting]![PartNumber]=" & [cmbPartNumber1])
=DLookUp("CuttingStep1","tblCutting","[PartNumber]=" & [cmbPartNumber1])
None of these have worked and I have no idea why. Any suggestions?
Or am I way off on how this is supposed to work?
Edit: added field types above.
Text values need to be delimited:
=DLookUp("CuttingStep1","tblCutting","PartNumber='" & [cmbPartNumber1] & "'")
Also, since your textboxes are using a calculated formula, they are "Unbound", therefore you need to update their contents yourself.
To handle this you'll need an event sub for the "Change" event of your ComboBox. Add the following code or similar, since I do not know the names of your Textboxes. Add to your Form Module:
Private Sub cmbPartNumber1_Change()
' Refresh (recalculate) values. textBox1,2,3 are names of your Textboxes that contain calculated values based on value of cmbPartNumber1.
textBox1.Refresh
textBox2.Refresh
TextBox3.Refresh
End Sub

SSRS Displaying Variable Data in a Page Header Not Displaying on Subsequent pages

I have inserted a page header and added a textbox with the expression =ReportItems!co_MainContact.value. This is the address that I want repeated in each page. For some reason, the address is printed on the first page, but not in the next few pages. Is there a reason why this data doesn't show up? I have a logo and a title in the header page and they're showing up in subsequent pages.
The co_MainContact expression is:
=Fields!co_Address1.Value & vbcrlf + Fields!co_City.Value & ", " & Lookup(Fields!co_ProvinceId.Value,Fields!pc_id.Value, Fields!pc_ProvCode.Value, "Province") & ", "& Fields!co_PostalCode.Value & vbcrlf & "Voice: "&Fields!co_MainContact.Value + " Fax: "& Fields!co_FaxNumber.Value & vbcrlf & "Toll Free: "&Fields!co_PhoneNumber.Value
Report Header properties are default settings and I'm using MS report builder 15.0.19440.0
Without seeing your full report design it's hard to say, if this does not help, please post a screen shot of your full report design, include all grouping as this is usually an important factor.
I would guess you are referencing a textbox that only appears on the first page. References to ReportItems don't work in the same way as referencing Fields.
So I would think you have a few options...
Option 1: Change the header expression
Change the expression in the header to be similar to the expression of the co_MainContact textbox but specify the scope as the dataset.
something like
=FIRST(Fields!co_Address1.Value, "myDataSetName") & vbcrlf + FIRST(Fields!co_City.Value , "myDataSetName") & .... etc... etc
NOTE: the dataset name is case sensitive and must be enclose in quotes.
Option 2: Add a calculated field to your dataset
For a cleaner report you could add a new field to your dataset, either in the dataset query, appending all the relevant columns, or you could add in to the dataset fields as a calculated field (from the dataset properties window).
Either way you will end up with a new column and you can reference that column directly in both the co_MainContact textbox (simply =Fields!myNewAddressColumn.Value) and also in your header. For the header you would use something like =FIRST(Fields!myNewAddressColumn.Value, "myDataSetName")
Hopefully one of these options will do the trick, if not post as much as you can, especially the report design.

Opening form from combo box in another form

I have a form called DisplayForm. In that form is a combo box drop down that is at the top of column on the form where a label would usually go. I want to select an item from that drop down menu and use that bit of data to open another form. I have copied an example from the web, changed the names and can't get it to work. Here is the code;
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea=" & Me.AreaCBDrop
End If
Area is the name of the field in the query that is the recordsource for the form, but when I run it, it opens a msgbox that wants me to enter a peramater value. I also don't understand what the IF is about. I have tried this with and without the if but get the same result. Me.AreaCBDrop has the correct value in it, but the where does not work.
Thanks
Thanks
Your WHERE condition is expecting a text parameter, but you are not supplying the expected format, so it is asking for one.
Surround your Me.AreaCBDrop with single quotes, like this:
If Not Me.NewRecord Then
DoCmd.OpenForm "AreaForm", _
WhereCondition:="LArea='" & Me.AreaCBDrop & "'"
End If

Display Issue for filtering a combobox in a continuous form

I have a continuous form containing many records. Each record contains a combo box that has vba code filtering the viewable selections when it gains focus (it does this by changing the RowSource.
My problem is that if i click the combo box in record A and then click the combo box is record B, the display-filter for record B is applied to record A. I do not have this problem if I click another control in between clicking the combo boxes.
Why is the filter applied to A's combo box even though focus has (supposedly) been lost? And how do I prevent this display error from happening? The only solution I have now is to make an arbitrary control gain focus when focus for the combobox is lost, but obviously that can be annoying for the user...
Possibly relevant code (SuperintendentID is the name of my combobox):
Private Sub SuperintendentID_GotFocus()
'Filters SuperintendentID based on the task's division
Me!SuperintendentID.RowSource = "SELECT tblJoinDivisionSuperintendent.SuperintendentID, [FirstName] & "" "" & [LastName] AS Name, tblJoinDivisionSuperintendent.DivisionID FROM tblSuperintendent RIGHT JOIN (tblDivision RIGHT JOIN tblJoinDivisionSuperintendent ON tblDivision.ID = tblJoinDivisionSuperintendent.DivisionID) ON tblSuperintendent.ID = tblJoinDivisionSuperintendent.SuperintendentID WHERE tblJoinDivisionSuperintendent.DivisionID = " & Me!DivisionID & ";"
Me!SuperintendentID = Me!SuperintendentID.ItemData(0)
Me!SuperintendentID = Me!SuperintendentID.OldValue 'Prevents a new value from being assigned when the control first gains focus
End Sub
You might be firing both the GotFocus events for comboboxA and comboboxB, but the screen is only showing you the last value you changed.
You could add use a Form.Repaint method (where Form=your form object) as part of the GotFocus event to ensure that the screen was refreshed after changing the underlying datasource.
You could test this to make sure both events are firing by putting a debug.print statement in the event as well, such as debug.print "GotFocus ComboboxA"

cascading combo box causing empty fields in next record

I'm having problems with a cascading combo box. Everything works fine with the combo boxes and the values get populated correctly.
Private Sub cmbAdjComp_AfterUpdate()
Me.cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID,
AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2,
AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4,
AdjusterCompanyOffice.Address5 FROM" & _
" AdjusterCompanyOffice WHERE
AdjusterCompanyOffice.AdjCompID = " & Me.cmbAdjComp.Column(1) & _
" ORDER BY AdjusterCompanyOffice.Address1"
Me.cboAdjOff = Me.cboAdjOff.ItemData(0)
End Sub
The secondary combo box has a row source query:
SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1,
AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3,
AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM
AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1;
Both comboboxes have the same controlsource.
Everything works fine and dandy moving between records and the boxes show the correct fields for each record.
When i use the first combo box, and then select the appropriate option in the second combo box, everything works great on the specific record.
However when I move to the next record, the values in the second combo box are all empty. If i close the form and reopen it, and avoid using the cascading combo boxes all the values are all correct when i move between records.
Somehow using the cascading combo boxes creates a conflict with the row source of the secondary combo box.
Hope that is clear! Have been rummaging around for an answer but cant find anything.
any help would be greatly appreciated.
Thanks
Noel
The reason why the combo box is blank when you navigate to the next record is because you have NotInList set to TRUE (which is what you want), but when you arrive on the record, the rowsource has been filtered to not include the value stored in the field the combo box is bound to. Thus, it's blank -- the value is there, but it can't be displayed, since it's not in the list.
To fix this, you need to clear the filter on the second combo box. To do that, in the OnCurrent event of your form, set the rowsource of the filtered combo box to be unfiltered:
Me!cboAdjOff.RowSource = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice ORDER BY AdjusterCompanyOffice.Address1"
I usually handle this by creating two constants at the top of the form's module, one for the SELECT statement and one for the ORDER BY:
cstrRecordsourceSelect = "SELECT AdjusterCompanyOffice.ID, AdjusterCompanyOffice.Address1, AdjusterCompanyOffice.Address2, AdjusterCompanyOffice.Address3, AdjusterCompanyOffice.Address4, AdjusterCompanyOffice.Address5 FROM AdjusterCompanyOffice"
cstrRecordsourceOrderBy = "ORDER BY AdjusterCompanyOffice.Address1"
Then it's much easier to handle. In the OnCurrent it looks like this:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & " " & cstrRecordsourceSelect
...and in the AfterUpdate of your first combo box:
Me!cboAdjOff.RowSource = cstrRecordsourceSelect & _
"WHERE AdjusterCompanyOffice.AdjCompID = " & Me!cmbAdjComp.Column(1) & _
" " & cstrRecordsourceSelect
This makes the code easier to read, and it also makes it easier to alter the rowsource if you need to, since you have to edit only the constant.