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?
Related
My code is working, but I just want to know if there is a more efficient way to achieve the same effect.
I have this layout in a form:
In my effort to foolproof the record creation process, I would like to have the "Save and Clear fields" button enabled only after all but the 'Comment' textbox/combobox contains some valid data.
The text/combo boxes are called txtBatteryID, cmbModelNumber, cmbChemistryType, txtSpecVoltage, txtSpecCapacity.
My code is as follow
Private Sub EnableSaveBtnCheck()
'this checks if the required fields contains valid data, if so, enables the save button.
If Me.btnSaveAndCLear.Enabled = False Then
If IsNull(txtBatteryID) = False And IsNull(cmbModelNumber) = False And IsNull(cmbChemistryType) = False And IsNull(txtSpecVoltage) = False And IsNull(txtSpecCapacity) = False Then
Me.btnSaveAndCLear.Enabled = True
End If
End If
End Sub
As you can see, I did the most straightforward way of using AND to combine all must-have conditions in an IF statement. This sub is called in After_Update() event of each text/combo box. Like this:
Private Sub cmbChemistryType_AfterUpdate()
Call EnableSaveBtnCheck
End Sub
My question, in the end, is: Is there a more efficient way to setup the condition "all text/combo box need to have something valid in them"? And is there a more elaborate way to check if the condition is met (something like a event on the form itself)?
Add the values of those 5 fields. If any of them is Null, the sum will be Null. So you only need call IsNull() once.
If IsNull(txtBatteryID + cmbModelNumber + cmbChemistryType + txtSpecVoltage + txtSpecCapacity) = False Then
In Excel VBA change option in the HTML select tag, I used the following code to change options within the <select> tag:
For Each objOption In objIE.Document.GetElementsByTagName("table")(0).GetElementsByTagName("td")(tdNode).GetElementsByClassName("txt_input1")(0).Options
If objOption.Value = SelQ Then
objOption.Selected = True
objIE.Document.GetElementsByTagName("table")(0).GetElementsByTagName("td")(tdNode).GetElementsByClassName("txt_input1")(0).OnChange
Else
objOption.Selected = False
End If
Next
This seems to work for web sites with nested <table> tags, but the web site was updated without the tags, so, to compensate for finding the selected option, I used this:
For Each objOption In objIE.Document.getElementById("frmProduction").elements.namedItem("WQ").Options
If objOption.Value = strVal Then
objOption.Selected = True
objIE.Document.getElementById("frmProduction").elements.namedItem("WQ").onchange
Exit For
Else
objOption.Selected = False
End If
Next
This is giving me the following error: Run-time error '5002': Application-defined or object-defined error
I used the above solution because it worked in another Internet Explorer application that used <frames> tags, so I modified it a little:
objIE.document.frames("DemographicsIFrame").document.GetElementByID("DropDownPayerID").value = PayerID
objIE.document.frames("DemographicsIFrame").document.GetElementByID("DropDownPayerID").onchange
I've tried to get around it with no success. I can get the selected option to change, but that's it. It won't update the page with required info related to the selected option. In the example above, that's what the onchange event was used for...to change the page contents after the PayerID was updated.
Any advice on how to make this work?
We were actually able to come up with a solution:
For Each objOption In objIE.document.getElementById("frmProduction").elements.namedItem("WQ").Options
If objOption.Value = strVal Then
objOption.Selected = True
Set evtFiroz = objIE.document.createEvent("HTMLEvents")
evtFiroz.initEvent "change", False, True
objIE.document.getElementById("WQ").dispatchEvent evtFiroz
Exit For
Else
objOption.Selected = False
End If
Next
I have the code below which is supposed to enable and disable the amount field on the main form and the purchases and sales subforms based on the value in the transaction type field. Now it works perfectly on the forward run. I.e. as soon as the form is loaded and i am scrolling from the first record to the last. But as soon as i hit the last record and i am scrolling through the records from back to front, the amount field remains disabled (i.e. the code no longer runs) and I have to reload the form. Is there a way I can solve this? I would like the user to have a realtime response with respect to the enabling and disabling.
Please find a picture of the form just in case it helps visualize the scenario.
Private Sub Form_Current()
Select Case Me.transactionType.Value
Case 1
Me.PurchaseOrderDetails_subform.Enabled = False
Me.SalesOrderDetails_subform.Enabled = False
Case 4
Me.Amount.Enabled = False
Me.PurchaseOrderDetails_subform.Enabled = False
Me.SalesOrderDetails_subform.Enabled = True
Case 2
Me.Amount.Enabled = False
Me.PurchaseOrderDetails_subform.Enabled = True
Me.SalesOrderDetails_subform.Enabled = False
Case 3
Me.Amount.Enabled = False
Me.PurchaseOrderDetails_subform.Enabled = False
Me.SalesOrderDetails_subform.Enabled = True
End Select
End Sub
I will truly appreciate your help.
You never enable that field, so you may need this modification:
Select Case Me.transactionType.Value
Case 1
Me.Amount.Enabled = True
Me.PurchaseOrderDetails_subform.Enabled = False
Me.SalesOrderDetails_subform.Enabled = False
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!
We're using SSRS 2008 R2
We have several reports that call multiple stored procedures. It seems that as soon as the report is called its runs the stored procs with their default values then reruns the stored procs with the passed parameters. Does that make sense?
We're considering using snapshots to store a snapshot of report with all the default parameters but is there a better way?
rptViewer.ProcessingMode = ProcessingMode.Remote
rptViewer.ShowCredentialPrompts = False
rptViewer.ShowBackButton = False
rptViewer.ShowDocumentMapButton = False
rptViewer.ShowExportControls = False
rptViewer.ShowFindControls = False
rptViewer.EnableViewState = True
rptViewer.ShowPageNavigationControls = False
rptViewer.ShowParameterPrompts = True
rptViewer.ShowRefreshButton = False
rptViewer.ShowPrintButton = True
rptViewer.ShowPromptAreaButton = False
rptViewer.ShowToolBar = True
rptViewer.ShowZoomControl = False
rptViewer.SizeToReportContent = True
rptViewer.AsyncRendering = False
rptViewer.Height = Unit.Percentage(100)
rptViewer.Width = Unit.Percentage(100)
Dim RepParameters As New ReportParams
With RepParameters
.ApplicationID = MyBase.CurrentApplicationID.ToString
.EntityID = EntityIDList
If ShowTitle Then .isExported = "True" Else .isExported = "False"
.LanguageID = CShort(MyBase.CurrentLanguage.ID).ToString
.UserSecurityID = CInt(MyBase.CurrentLoggedUser.SecurityID).ToString
End With
**rptViewer.ServerReport.SetParameters(rep.SsrsReportParameters(RepParameters))**
Sounds like you are passing your parameters too late for the reportviewer control. Make sure in the page's execution cycle you are setting them preferably as soon as possible. I worked around this problem by initialising the ReportViewer control in the page load code behind code rather than declaring one in the aspx part. This solved it for me.
More of a workaround than a solution.
We ended up setting the default value to one of the parameters to -1 and in the stored procedure we only run the code if the parameter is not -1.