Hide Detail Field Depending other variable in Access Report View (Not Print View) - ms-access

I have a tabbed control (TabCtl45) in the "Detail" section of my report that that has three tabs. (Page1, Page2, Page3). I only want to show one page depending on another variable known as Fee Type. If FeeType = 1, then Page1 tab shows. If FeeType = 2, then page Page2 tab shows... etc.
I was able to make this work in "Print View" with the OnFormat event; however, I want all my data in one easy flowing page like report view. Not in separate pages like print view outputs.
The code looked like this:
If Me.FeeType = "1" Then
Me.TabCtl45.Pages("Page1").Visible = True
Me.TabCtl45.Pages("Page2").Visible = False
Me.TabCtl45.Pages("Page3").Visible = False
ElseIf Me.FeeType = "2" Then
Me.TabCtl45.Pages("Page1").Visible = False
Me.TabCtl45.Pages("Page2").Visible = True
Me.TabCtl45.Pages("Page3").Visible = False
ElseIf Me.FeeType = "3" Then
Me.TabCtl45.Pages("Page1").Visible = False
Me.TabCtl45.Pages("Page2").Visible = False
Me.TabCtl45.Pages("Page3").Visible = True
End If
How do you I get this code to work in report view from the "Detail" section of my report? There is no event that I can see working for this purpose in the properties "Detail" section.

You can't. The Report View is rather limited, the section events (like Detail.OnFormat) simply don't run in this view. Only in Print/Print Preview.
The only thing you can do to format single records in Report View is Conditional Formatting, but that's no use to hide things.
On an unrelated note, you can simplify your code a lot by doing:
Me.TabCtl45.Pages("Page1").Visible = (Me.FeeType = "1")
Me.TabCtl45.Pages("Page2").Visible = (Me.FeeType = "2")
Me.TabCtl45.Pages("Page3").Visible = (Me.FeeType = "3")

Related

Using Split form to update data

I have 2 tables, Tbl_Store1 & Tbl_Store2
I have one form (Frm_Data) that will populate from Tbl_Store1 or Tbl_Store2 based on an unbound text box called Txt_TblToUse.
Txt_TblToUse is a drop down field that only offers the user 2 choices. Store1 or store2.
After the user selects or changes Txt_TblsToUse I have the program set to update the data source to the correct table and then refresh, requery and repaint the form.
The frm_Data has a default view as a "Split Form"
The left side of the form is Form View
The Right side of the form is DataSheet View
The left side of the form (Form View) updates correctly
The right side of the form (DataSheet View) does not update to the new data.
If I right click on a header of one of the DataSheet view fields then chose to sort it, the data then re-populates with the correct data.
Is there a way to consistently update the data on the datasheet part of the form?
Code***
Call TableToUse 'This will look in the Module1 and determine which table to use
**TableToUse Code
Public Function TableToUse()
Form_Frm_Data.RecordSource = ""
Dim M_Month As Integer
M_Month = Form_Frm_Data.Txt_Month
Select Case Form_Frm_Data.Txt_TblToUse
Case Is = "Store1"
Form_Frm_Data.RecordSource = "Qry_Store1"
Form_Frm_Data.Requery
Case Is = "Tbl_Store2"
Form_Frm_Data.RecordSource = "Qry_Store2"
Form_Frm_Data.Requery
End Select
Dim db As String
db = ""
db = Form_Frm_Data.RecordSource
Form_Frm_Data.OrderBy = "TransactionDate ASC"
Form_Frm_Data.OrderBy = "TransactionDate DES"
Form_Frm_Data.Txt_DB = db
Form_Frm_Data.Recalc
Form_Frm_Data.Refresh
Form_Frm_Data.Repaint
Form_Frm_Data.ID.ColumnHidden = True
End Function

VBA enabling text and combo box in MS Access

I'd like to make a text box (Text28 hereafter) and a combo box (combo43 hereafter) enabled when another combo box (Combo26) takes the value "Resolved"
So this is the code, written in VBA, that should do that :
Private Sub Combo26_AfterUpdate()
If Combo26.Value = "Resolved" Then
Me.Text28.Enabled = True
Me.Combo43.Enabled = True
Else
Me.Text28.Enabled = False
Me.Combo43.Enabled = False
End If
End Sub
Unfortunatly, nothing happens when I try it. Would you have a idea ?
Thx
If you are pulling two columns as your row source (as indicated in your comment above), it looks like the first one that is displayed is the ID. You should target the second column to do your comparison, e.g.,
If Combo26.Column(1) = "Resolved" Then
...
That works for me!
Combo26.Column(0)
will give you the ID.

Forms/ VBA - activating controls based on status

This question isn't particularly technical, it's more theoretical.
I'm doing the "project queue" thing in Access that I think we all do from time to time. We've got several steps to go through. I'm hiding buttons that don't make sense in a given step and adding a star to the most relevant tab. For example, if I have been assigned development of a project, the "move to production" button is hidden and disabled because I need to go through testing before I can move the project to production. I also rename the development tab to Development* to queue me to that.
Everything was hardcoded in VBA and it still can be but it's getting longer and uglier to maintain. I'm wondering if someone has a best practice or just general suggestion. I had 6 statuses but I'm going to 12 and feel like it's time to think about doing this better.
When a button is clicked you get a code block like this:
Private Sub AssignScoping_Click()
Me.RequestStatus.Enabled = True
Me.RequestStatus = "Scoping"
Me.RequestStatus.Enabled = False
End Sub
Each button just assigns a different text value to the RequestStatus field which drives the rest of the logic which looks like this:
Private Sub setButtonAvailability()
Select Case Me.RequestStatus
Case Null
Me.PlaceInQueue.Visible = True
Me.PlaceInQueue.Enabled = True
Me.AssignScoping.Visible = False
Me.AssignScoping.Enabled = False
Me.AssignDevelopment.Visible = False
Me.AssignDevelopment.Enabled = False
Me.AssignTesting.Visible = False
Me.AssignTesting.Enabled = False
Me.AssignProduction.Visible = False
Me.AssignProduction.Enabled = False
Me.AssignAutomation.Visible = False
Me.AssignAutomation.Enabled = False
Me.Tabs.Pages("Intake").Caption = "Intake" & "*"
Me.Tabs.Pages("Scoping").Caption = "Scoping"
Me.Tabs.Pages("Development").Caption = "Development"
Me.Tabs.Pages("Testing").Caption = "Testing"
Me.Tabs.Pages("Production").Caption = "Production"
Me.Tabs.Pages("Automation").Caption = "Automation"
...
Case Else
Me.PlaceInQueue.Visible = True
Me.PlaceInQueue.Enabled = True
Me.AssignScoping.Visible = True
Me.AssignScoping.Enabled = True
Me.AssignDevelopment.Visible = True
Me.AssignDevelopment.Enabled = True
Me.AssignTesting.Visible = True
Me.AssignTesting.Enabled = True
Me.AssignProduction.Visible = True
Me.AssignProduction.Enabled = True
Me.AssignAutomation.Visible = True
Me.AssignAutomation.Enabled = True
Me.Tabs.Pages("Intake").Caption = "Intake"
Me.Tabs.Pages("Scoping").Caption = "Scoping"
Me.Tabs.Pages("Development").Caption = "Development"
Me.Tabs.Pages("Testing").Caption = "Testing"
Me.Tabs.Pages("Production").Caption = "Production"
Me.Tabs.Pages("Automation").Caption = "Automation"
End Select
End Sub
I figure there are a ton of options including putting some of the controlling info in a table for just that purpose but thought I'd bounce it off your collective noggins for suggestions as I tend to work in isolation at my job and I don't always think of the best way to do something, just the way I can do it right now.
Textbox and combobox can employ Conditional Formatting rules to set enabled/disabled state.
Doesn't matter what approach is taken, still have to 'touch' each control to set its property. One approach is to generically loop through controls collection without having to explicitly reference each control by name and set the Enabled or Visible properties according to some criteria. Use of control's Tag property might be helpful. Example:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCommandButton Then
ctl.Visible = ctl.Tag = Me.RequestStatus
End If
Next ctl
Another approach is to give controls similar name, like btnProj1, btnProj2, etc. Then loop could be limited to that set of controls:
For x = 1 to 10
Me.Controls("btnProj" & x).Visible = Me.Controls("btnProj" & x).Tag = Me.RequestStatus
Next
If you set a control not visible, why bother with the Enabled property?

How do you update a selected dropdown value using VBScript

I am trying to problematically change the dropdown selection on an InternetExplorer.Application then save that selection. The code I have so far is
dim myValue
myValue="3"
for j = 0 to obj.Options.length - 1
if(obj.Options(j).Value = myValue) then
obj.Options(j).selected = true
exit for
end if
next
This works on the current pages dropdown list, however when I click save, the value "3" isn't saved and it reverts back to its original value when I reload the page.
Another thing to mention is that when I manually click the dropdown and select a value then save, it does update to the new value when I reload the page. I have tried the obj.click function on it but I do not believe a programmatic mouse click works like a actual mouse click with the action listener.
My guess would be something to do with the databinding between the new value selection and the action listener for the page. I am fairly new to vbscript and have tried all sorts of different things.
Any help would be very much appreciated. Thank You!
Supposing you have the obj object set properly, e.g. something like
set obj = ie.document.getElementById("my_dropdown") then you should ensure that only one option is selected:
for j = 0 to obj.Options.length - 1
if (obj.Options(j).Value = myValue) then
obj.Options(j).selected = true ''' do not exit for
else
obj.Options(j).selected = false
end if
next
or
For Each opt In obj.Options
If opt.Value = myValue Then
opt.Selected = True
Else
opt.Selected = False
End If
Next
Caution: above code snippet could result to (undesired?) case that no option remains selected!

How to perform font changes to a report using an option box

I am having issues trying to use an option box to change a font on a series of controls. Basically, I have a report (named Q_tblProject52Week) embedded in a form. I have embedded an option box within the form (called "cornice33) which aims to change the font on the two controls (testo107 and testo108) embedded in the report.
At the moment I am trying the following with no success:
If Cornice33 = 1 Then
testo107.FontName = "calibri"
testo108.FontName = "times"
ElseIf Cornice33 = 2 Then
testo107.FontName = "times"
testo108.FontName = "calibri"
End If
I am getting a missing object message (it is not recognising the controls testo107 and testo108). Also important to note, the report is embedded in a folder control.
You need to tell access that you refer to a control on the report which is a child of your form.
If Cornice33 = 1 Then
Me.Q_tblProject52Week.testo107.FontName = "calibri"
Me.Q_tblProject52Week.testo108.FontName = "times"
ElseIf Cornice33 = 2 Then
Me.Q_tblProject52Week.testo107.FontName = "times"
Me.Q_tblProject52Week.testo108.FontName = "calibri"
End If
hope this helps