I have an access database which deals with "articles" and "items" which are all textual stuff. An article is composed of several items. Each item has a rich text field and I wish to display the textual content of an article by concatenating all rich text fields of its items.
I have written a VBA program which concatenates the items rich text fields and feeds this into an independent TextBox control on my form (Textbox.Text = resulting string) but it does not work, I get an error message saying "this property parameter is too long".
If I try to feed a single textual field into the Textbox control, I get another error stating "Impossible to update the recordset" which I do not understand, what recordset is this about ?
Each item field is typically something like this (I use square brackets instead of "<" and ">" because otherwise the display of the post is not right) [div][font ...]Content[/font] [/div]", with "[em]" tags also included.
In front of my problem, I have a number of questions :
1) How do you feed an HTML string into an independent Textbox control ?
2) Is it OK to concatenate these HTML strings or should I modify tags, for example have only one "[div]" block instead of several in a row (suppress intermediate div tags) ?
3) What control should I use to display the result ?
You might well answer that I might as well use a subform displaying the different items of which an article is made up. Yes, but it is impossible to have a variable height for each item, and the reading of the whole article is very cumbersome
Thank you for any advice you may provide
It works for me with a simple function:
Public Function ConcatHtml()
Dim RS As Recordset
Dim S As String
Set RS = CurrentDb.OpenRecordset("tRichtext")
Do While Not RS.EOF
' Visually separate the records, it works with and without this line
If S <> "" Then S = S & "<br>"
S = S & RS!rText & vbCrLf
RS.MoveNext
Loop
RS.Close
ConcatHtml = S
End Function
and an unbound textbox with control source =ConcatHtml().
In your case you'd have to add the article foreign key as parameter to limit the item records you concatenate.
The "rich text" feature of a textbox is only intended for simple text.
We use the web browser control to display a larger amount of HTML text, and load it like this:
Private Sub Form_Current()
LoadWebPreview
End Sub
Private Sub HtmlKode_AfterUpdate()
LoadWebPreview
End Sub
Private Sub LoadWebPreview()
' Let the browser control finish the rendering of its standard content.
While Me!WebPreview.ReadyState <> acComplete
DoEvents
Wend
' Avoid the pop-up warning about running scripts.
Me!WebPreview.Silent = True
' Show body as it would be displayed in Outlook.
Me!WebPreview.Document.body.innerHTML = Me!HtmlBody.Value
End Sub
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 set up an Excel form that auto-fills an HTML web form. I've figured out how to use VBA to get the elements and cycle through them to add values. My issue is with a text field that is revealed with the click of a check box. I can't have Excel check the box until after I've obtained the elements for the form.
I've looked at the html, and it looks like the field is hidden to some degree when the form is first loaded, as the id and everything can only be found in the tree once the box is checked. The problem is, this field won't show up in the VBA elements list no matter what I try. I've tried re-doing the Set command, and gotten an error when I do that. I'm not sure how to refresh the elements list in VBA to include the new input box.
I used the Set command to get all the elements
Set frm = ie.document.getElementByID("form1")
This is fine, but I can't use that same command to try to re-Set the element list. I get the run-time error 438 (Object doesn't support this property or method)
I tried making a Variant titled frm2, but I get the same error
Sub formFill()
Dim ie As Object
Dim frm As Variant
Dim element As Variant
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "THIS IS THE URL"
While ie.readyState <> 4: DoEvents: Wend
'Get form by ID
Set frm = ie.document.getElementByID("form1")
ie.Visible = True
For Each element In frm.elements
Select Case element.Name
Case "fv_RRFC$chkOtherModel"
element.Checked = True
element.FireEvent ("OnClick")
frm.getElementByID("fv_RRFC_txtOtherModel")(0).Value = "test model" 'I tried using the command here, but it didn't work
Case "fv_RRFC$txtRRFC_PROGRAM"
element.Value = "test"
Case "fv_RRFC$txtOtherModel"
element.Value = "test model"
'My attempt to add it to the Select Case. Not surprised this didn't work, as the for Each loop uses the list it had before
End Select
Next
End Sub
I expected to be able to re-load the elements list to interact and fill the newly revealed box, but I've had no luck finding a way to do that.
I am trying to get a text string from inside a div on a webpage, but I can't seem to figure out how it is stored in the element.
Set eleval = objIE.Document.getElementsByClassName("outputValue")(0)
Debug.Print (eleval.innerText)
I have tried this and variations thereof, but my string just reads as "".
I mainly need help on how is this type of data is referenced in VBA.
<div class="outputValue">"text data that I want"</div>
Here is a screenshot of the page in question, I cannot give a link since it requires a company login to reach.
With .querySelector method, make sure page if fully loaded before attempting.
Example delays can be added with Application.Wait Now + TimeSerial(h,m,s)
Set eleval = objIE.Document.querySelector("div[class="outputValue"]")
Debug.Print eleval.innerText
If it is the first of its className on the page you could also use:
Set eleval = objIE.Document.querySelector(".outputValue")
If there is more than one and it is at a later index you can use
Set eleval = objIE.Document.querySelectorAll(".outputValue")
And then access items from the nodeList returned with
Debug.Print eleval.Item(0).innerText 'or replace 0 with the appropriate index.
Dim elaval as Variant
elaval = Trim(Doc.getElementsByTagName("div")(X).innerText)
msgbox elaval
Where X is the instance of your class div
So I'm having some difficulties with this code. I know it's obnoxiously wordy, but every attempt I made to turn some of these form references into variables to save space ended with me having even less functionality than before.
Basically what I've done so far is create a navigation form with several tabs, one to create a ticket, one to resolve/edit a ticket, and one to search the tickets. The search tab is basically a continuous form that updates based on the search criteria I enter. My goal is that when I click on the ticketID for each record, it will take me to the selected record on the Resolve/Edit Ticket page (on that page I have a combo box [called cboGoToRecord] where you can select the record you want).
I have a hyperlink in place that takes the user to the Resolve/Edit page and code that works ONLY when the line I've denoted with four asterisks (for clarity) is replaced with
rst.FindFirst "ticketID =" & [some number].
When I do that, the results are as expected. If I leave it as it is below, every record looks up the first record (A Debug.print check shows that the value of this field is apparently always 1...) So I guess what I need to figure out is how do I access the ticketID hyperlink's value so that I can put it on that line and make my code function effectively? I apologize if this is overly detailed but figured too much was better than not enough.
Private Sub ticketID_Click()
'Takes user from Search Tickets to Resolve/Edit Issues tab
DoCmd.BrowseTo acBrowseToForm, "frmResolveIssues", "frmBrowseTickets.NavigationSubform"
On Error Resume Next
Dim rst As Object
Set rst = Forms!frmBrowseTickets!NavigationSubform.Form.RecordsetClone
[Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value = [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
****rst.FindFirst "ticketID =" & [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
Forms!frmBrowseTickets!NavigationSubform.Form.Bookmark = rst.Bookmark
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
End Sub
Edit:
After altering my form to add a separate hyperlink and referencing the static ticketID, I have concluded that everything I thought was true was not. Finding the value of a hyperlink was NOT the problem. The problem is that my ticketID value truly does insist on being one, and I have no clue how to fix that.
When this works:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![ticketID].Value
then also check out:
Debug.Print [Forms]![frmBrowseTickets]![NavigationSubform].Form![cboGoToRecord].Value
As June7, I never use the Navigation form. It complicates everything too much.
This question is mainly for curiosity, but also, in the description, I had intended to highlight an infrequently documented behavior of Access.
Background
When creating an Access report, we can use the On Format method of the detail section to modify values or properties per-record. For example, assume we want to hide a field label when the value is empty:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If (IsNull(Me.SomeField) Or Me.SomeField = "") Then
Me.SomeFieldLabel.Visible = False
Else
Me.SomeFieldLabel.Visible = True
End If
End Sub
What I did not realize about this until today is that the assignment .Visible = False does not modify the instance of the label in the Detail section, but rather is modifying the definition of the label on the report.
This can be demonstrated with the following modifiction to the code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If (IsNull(Me.SomeField) Or Me.SomeField = "") Then
Me.SomeFieldLabel.Visible = False
End If
End Sub
Assuming the label is initially visible (in form Designer), the event produces somewhat unexpected behavior: the label will remain visible until the first empty record; after that, it will remain hidden for all other records - I had originally expected that at each call of Detail_Format the controls where starting with their default definitions.
Question
Is there any way to reference the particular instance of a control within the Detail_Format event?
In this simple case of visible true/false, this is easily handled by just a simple if-then-else, but I can imagine more advanced scenarios where one might want to leave the default values in tact.
I don't believe so, in all of my experience, properties of report objects always apply universally across the report, not to specific instances of the abject (if the object is repeated).
For your example, I would use a text box instead of a label to label the field, and use something like =IIf(IsNull(Field1), "", "Label:") for the controlsource. That way it won't show anything if the field is null, yet still show the label text if there is a value.