This application is Access 2010, with a SQL backend.
I have a form, which has a tab control, with 2 pages. 1 page has 1 listbox and the other has 2 listboxes. I use some code, on change of the tab control, to determine the active page, and set the listbox(es) row source(s) for the one(s) on the active page, and clear it out on the inactive page. This takes a sec and the listboxes look yucky while this is happening.
To prevent the user from seeing this, I made a text box, with a colored background and the control source ="Please Wait One Moment..."
with like 48 font. On load of the form, this textbox is visible = false. On click of the tab control, the text box is to be made visible, and it is big enough to cover then entire tab control. It does cover the tab control, but I can still see the listboxes through the text box. The text box has a back color and is not transparent. I tried right-clicking the listboxes in design view and choosing Position - Send to Back, and right-clicking the textbox and choosing Position - Send to Front.
This doesn't seem to work. Is anyone familiar with this issue? Figuring someone has tried a trick like this.
The meat of my code is all functioning properly, for this on change of the tab control. I have this code at the beginning:
DoCmd.Hourglass True
Me.txtPleaseWait.Visible = True
Me.Repaint
Application.Echo False
Debug.Print Me.txtPleaseWait.Visible
and this at the end:
Application.Echo True
Me.txtPleaseWait.Visible = False
Me.Repaint
Debug.Print Me.txtPleaseWait.Visible
DoCmd.Hourglass False
Debug.Print "got to end of resting form state"
Does that make sense?
Should I handle this differently?
Thank you.
Edit
I found that listboxes have a higher zorder than textboxes, so I changed my textbox to a listbox. I still see the listboxes from the tab control, through the listbox I'm using to cover them up.
Is there a control that would better cover these and could have this "intermission" type message show, while the listboxes are being set and unset?
I researched different aspects of this, and found the listbox has a higher zorder than text boxes, which is position front or back relative to other objects. I tried just doing this onload of the form, and there wasn't time to hide anything. It just waited to load the form, until the rowsources were set.
Since the find tab is the default one, and quicker to load, I just load that on load. Then, if someone clicks on the other tab, I will load the add listboxes. I also set an integer variable to 0 on load of the form. When I click on the tab to go to the add page (add page is active), I check that variable, and if it is 0, I set the row source, and then +1 to the variable. Next time I click on it, I don't re-order it.
This way, I'm not using resources to load and unload the listboxes, and I only load 2 of them, if the user even goes to that tab. Many times, they might just be looking for one in the system, and going to view it.
Here is the full code, in case this method helps someone else. You could also make the variable boolean, and just set it to true, and then false.
Option Compare Database
Option Explicit
Dim AddLoaded As Integer
Property Get ActivePage() As Access.Page
'PROPERTY TO IDENTIFY WHICH TAB WE ARE ON, FOR FILTERING AND IDENTIFYING WHICH ACTIVE LISTBOX TO LOOK AT, FOR VALUES AND ACTIONS
With Me.tbAddFind
Set ActivePage = .Pages(.Value)
End With
End Property
Private Sub Form_Load()
Dim Listctrl As Control
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Dim cSQL As String
AddLoaded = 0
For Each Listctrl In Form.Controls
If (Listctrl.ControlType = acListBox) Then
With Listctrl
.RowSource = ""
End With
End If
Next Listctrl
Me.tbAddFind.Value = 0
cSQL = "SELECT vw_CMP_Projects.CM_CID, [vw_CMP_Projects]![ProjectName] &" & Chr$(34) & " (" & Chr$(34) & "& [vw_CMP_Projects]![ProjectNo] &" & Chr$(34) & ") " & Chr$(34) & " AS Projects FROM vw_CMP_Projects ORDER BY [vw_CMP_Projects]![ProjectName] &" & Chr$(34) & " (" & Chr$(34) & "& [vw_CMP_Projects]![ProjectNo] &" & Chr$(34) & ")" & Chr$(34)
Me.lstProjects.RowSource = cSQL
Me.lstProjects.Requery
End Sub
Private Sub tbAddFind_Change()
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Select Case Me.ActivePage.Name
Case "pgAddProjects"
If AddLoaded = 0 Then
cmd.ActiveConnection = GetCatalog()
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "sp_RefreshProjectsAdd"
cmd.Execute
Me.lstAllProjects.RowSource = "Select * From qryAddProjectsYes"
Me.lstAllProjects.Requery
Me.lstAddProjects.RowSource = "Select * From qryAddProjectsNo"
Me.lstAddProjects.Requery
AddLoaded = AddLoaded + 1
End If
End Select
End Sub
Thanks for the discussion. It was helpful, as it gave me things to research.
Related
I have a subform that is a continuous form that lists the text elements for each record in the parent form. In this case, the parent form lists a particular claim number, and the subform provides the text elements of that claim. I found some clever code online that uses an unbound text box on top of the text element to reproduce the claim text but with a select word highlighted. The particular word comes from a related list of words. But sometimes, the word in the claim is not exactly the same as the word on this list. For example the word on the list might be "run" but I also want to highlight "running" or "runs." I've explored various ways to identify different variations like, for example finding "run" in the text and then finding the rest of the word using InStr() and Mid(), etc. This worked, in general, but only for the first record. Even though the basic process works for all the records in the continuous form, I can't figure out how to programmatically look at the text of each individual record to evaluate what I need to search for. I've tried some RecordSet looping, but it seems to always just look at the first record.
Looking at some other posts I get the feeling that this might not be possible, but would appreciate any insight. The code below works. Just trying to figure out how to adapt this so I can work with text in the individual records and highlight variations of a word.
Thanks.
Public Sub Form_Current()
Dim ctl As Control
On Error GoTo Err_Handler
'Purpose: Highlight matches in txtSearchDisplay.
Dim strField As String 'The field to search
Dim strSearchValue As String 'The value to find
Dim strControlSource As String 'ControlSource for displaying match.
Const strcWildcard = "*" 'Some other back ends use %
'HTML tags for highlighting matches. Could be just "<b>" and "</b>".
Const strcTagStart = "<font color=""""red"""">"
Const strcTagEnd = "</font>"
'Search for claim term value in claim element text.
strField = "ClaimElementText" 'Field containing claim text
strSearchValue = Forms![frmWords].ClaimTerm 'This is the word to highlight
'Control Source for the text box to display matches.
strControlSource = "=IIf(" & strField & " Is Null, Null, " & _
"Replace(" & strField & ", """ & strSearchValue & """, """ & _
strcTagStart & strSearchValue & strcTagEnd & """))"
With Forms![frmWords]![sbfmClaims].Form![sbfrmClaimText].Form!txtSearchDisplay
.ControlSource = strControlSource
.Visible = True
.BackColor = RGB(255, 255, 255)
End With
'This is necessary to get the term highlighting to show up on first limitation.
Forms![frmWords]![sbfmClaims].Form![sbfrmClaimText].Form!txtSearchDisplay.SetFocus
Exit_Handler:
Exit Sub
Err_Handler:
Resume Exit_Handler
End Sub
I'm trying to fill out a form using VBA (just to get more skilled in programming with VBA). I noticed that the web form is not updating a hidden field when a radio button is checked via VBA.
To be more specific, the hidden field doesn't become visible after checking the radio button.
In my research to why that is I read that: "Events won't (usually) fire when you change the data programmatically". When this assumption is true, what's the difference between filling out a form manually or programmatically? But when this assumption is wrong, what adjustments do I need to make in my code in order to make hidden fields visible after clicking that radio button?
The website I'm working with is from the Dutch Tax authorities:
https://www.belastingdienst.nl/wps/wcm/connect/nl/auto-en-vervoer/content/hulpmiddel-motorrijtuigenbelasting-berekenen
This is my code.
Sub Show_Hidden_Field()
'Declaration section
Dim htmlDoc As New MSHTML.HTMLDocument
Dim objShell, objShellWindows, objShellWindow As Object
Dim htmlOption As MSHTML.IHTMLElement
'Wait an extra 3 seconds so you can switch to the IE window
'and see what's going on
Application.Wait Now + TimeValue("0:00:03")
'Find the correct Internet Explorer window
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
For Each objShellWindow In objShellWindows
If objShellWindow.Name = "Internet Explorer" Then
'Find this window
If objShellWindow.LocationURL = "https://www.belastingdienst.nl/wps/wcm/connect/nl/auto-en-vervoer/content/hulpmiddel-motorrijtuigenbelasting-berekenen" Then
'This the correct page. Get the content of page
Set htmlDoc = objShellWindow.document
Exit For
End If
End If
Next objShellWindow
'Find the radio button . . .
Set htmlOption = htmlDoc.getElementById("V1-1_True")
'. . . and check it.
htmlOption.Checked = True
'**********************************************************************
'I've also tried these options without succes.
'htmlOption.Click
'htmlOption.FireEvent ("onchange")
'Or set the focus to another field
'**********************************************************************
End Sub
You have a couple issues with your code. The first one is that you are using the wrong type for your radio button element.
While htmlOption is technically a MSHTML.IHTMLElement, it more specifically should be of type: MSHTML.HTMLInputElement. So change your declaration to:
Dim htmlOption As MSHTML.HTMLInputElement
For your actual issue, you should just use .Click. Taking a look at developer.mozilla.org:
The HTMLElement.click() method simulates a mouse click on an element.
When click() is used with supported elements (such as an <input>), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events. (emphasis added)
So, you wouldn't need to use .Checked = True, because upon clicking the input element, you will not only solve your problem with the hidden area being revealed, you are also simultaneously changing the value to True.
So you would just use this:
'Find the radio button . . .
Set htmlOption = htmlDoc.getElementById("V1-1_True")
'. . . and check it.
htmlOption.Click
I want to click on a button in IE (which probably is not actually a button) using VBA. The problem is that there is no ID or name in the source of the "button" I want to click on.
Here is the part of the source of the webpage (see link):
Part of source (NEW)
I want to click on the part which has as text: "Informatie" in it. Im currently using the following code (just a part of it) in VBA. But when i excecute the code, nothing happens, not even an error message:
Dim e
Set e = HTMLDoc.getElementsByClassName("BackgroundApp")(0).getElementsByTagName("Div")(7).getElementsByTagName("td")(0)
e.Click
Hard to help without actual page, so I replicate it and here is the tested code:
Dim IE as Object
Dim objCollection As Object
Dim tdNode As Object
Set objCollection = IE.document.getElementsByTagName("td")
For Each tdNode In objCollection
If InStr(1, tdNode.innerHTML, "Informatie", vbTextCompare) > 0 Then
' "Informatie" button is found
tdNode.Click ' click it
Exit For
End If
Next tdNode
Give it a try and report back.
I'm working on a legacy VB6 application. I'm sure this probably relates to VB.NET so i will tag it, but please let me know if it's completely different(which I dont think it is) then I'll remove the tag to avoid confusion.
Here is my issue....
I have a Tab control with multiple tabs: 0 - 3. On TabStuff.Tab = 0, I have a few textboxes and comboboxes. The user uses keyboard TAB to move from Indexed controls. What happens is once they get to the last control which is a textbox called txtCity - and click keyboard TAB once more, it brings them to TabStuff.Tab=1.
My issue is I do VALIDATE on txtCity - I call a function that verifies that a couple of the fields aren't NULL and if one of the fields is in fact NULL then I show a MSgBox and try to setFocus on that control. But instead, when OK is clicked on msgbox, it goes to the next tab which is TabStuff.tab=1 which is not correct.
Here's some of my code...
Dim FirstName, City as String
flag=false
firstName = txtName.text
city = txtcity.text
if FirstName="" or isnull(FirstName) then
msgbox "Please enter Name"
tabstuff.tab=0
txtname.setfocus
exit sub
elseif city = "" or isnull(city) then
msgbox "Please enter city"
tabstuff.tab=0
txtcity.setfocus
exit sub
end if
flag=true
This code is in txtCITY_VALIDATE
So in case city was empty, it shows MsgBox, stays on Tab=0 and setfocus on that control, but instead it goes to the next tab=1 and sets focus on the first control of that tab.
EDIT:
in txtCITY_LostFocus
If Flag = False Then
TabStuff.Tab = 0
Exit Sub
End If
I added this but it still goes to tabstuff.tab=1 setting the focus on first control of the tab
EDIT 2:
In a new project i created txt1 and txt2 - i set TabIndex 0 and 1 respectively.
Private Sub Txt1_Validate(Cancel As Boolean)
If Txt1.Text = "" Then
MsgBox "no text in txt1"
Txt1.SetFocus
End If
End Sub
This is the code I use. I click TAB on txt1 without entering any text, so this gets executed, but after msgbox, the focus gets set on txt2
For some extremely weird reason - i seem to have been getting this discrepancy because I was doign it in the VALIDATE property. When i entered the same code in LostFOCUS it seems to work fine. Thanks everyone for your help with this!
The script bellow is run by a button in an HTA form. Whenever the button is pressed, however, instead of seeing this ["Downloading: " & dlFileName], the program freezes, and remains frozen untill download is complete. I do see the 2nd message ["Download complete!"].
When I entered a MsgBox between the 2nd and 3rd line I did see the text changing into "Downloading..." before I pressed the OK button, but that's no solution now is it...
Am I writing it wrong, or is there a (simple, light) way to halt the action untill the previous action has been taken?
Any info is welcome, I'm rather new at this!
Sub Download_File(dlAddress, dlFileName)
strStatus.innerHTML="Downloading: " & dlFileName 'This does not show up.
strHttp.Open "GET", dlAddress, False
strHttp.Send
With createobject("Adodb.Stream")
.type = 1 '//binary
.open
.write strHttp.responseBody
.savetofile txtDLPath.Value & dlFileName, 2 '//overwrite
End With
strStatus.innerHTML="Downlad complete!"
End Sub
This is normal behavior in an HTA. What I do is use a sub called "sleepy" which produces a near-instant "delay" which pauses the script in a way that allows html updates to happen inside other routines.
Add a call to this function right after updating the InnerHTML.
Sub sleepy
Set objShell = CreateObject("WScript.Shell")
strCmd = "%COMSPEC% /c"
objShell.Run strCmd,0,1
End Sub