I have this code in an Access form:
Private Sub btnGenerateName_Click()
Me.txtName = Me.Family & " " & Me.Model & " " & Me.DimensionsText
End Sub
If the concatenated string is longer than 50 characters when I'm clicking the button throws an error:
"The field is too small to accept the amount of data you attempted to
add. Try inserting or pasting less data."
Isn't the text box length 255? Why I can't insert longer text?
You can find what they are explaining by doing the following:
Go to the supporting table's Design View
Select the field
Select Field Size limit (By default it is set to 50.)
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 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
First off I apologize for not knowing a lot about Microsoft Access forms. I have had very little involvement with them and this is only to support a legacy product that will soon be replaced.
I have a Microsoft Access form that has a detail section such as the image below (shown in Design View).
I believe the first 6 textboxes are bound to a data set, the last one is bound to nothing (I added it for what I'm trying to do). When I view the form in Form View I see many results (which come from the bound table). The only textbox that does not have info in it is the last one to the right (Unbound).
My goal is to just simply change the value and back color of the following textbox in red.
I want to edit the contents (change "jk" to "Error") and I want to change the background of that one textbox to RED (vbRed). The problem is when I try to change the backcolor it changes all the textboxes called "Errors" (that entire column).
ErrorHandler:
Forms![MyForm1]![Errors].BackColor = vbRed
If I want to get the value of the currently selected cell I can just do the following and it works fine...
MsgBox "Debug: " & Forms![MyForm1]![Code] 'The first column
MsgBox "Debug: " & Forms![MyForm1]![Name] 'The second column
MsgBox "Debug: " & Forms![MyForm1]![Number] 'The third column
MsgBox "Debug: " & Forms![MyForm1]![Errors] 'The Unbound (last column)
To edit and save individual records, the textbox must be bound to a field of the table.
So, add a field of Short Text to the table to hold your error message.
How do I display address values in one row in a Text Box?
Currently values are appear as multiple rows one under another for example:
5,Irivine Place
po box 2345
usa
I'm looking for something like:
5,Irivine Place,po box 2345,usa
If your address is one row in the database then linefeeds must also be being stored. You need to replace these with something else -i.e. a ", " e.g.
=Replace(Fields!Address.Value,VBCRLF,", ")
You would need to get rid of the final ", " in the line so it then becomes:
LEFT(Replace(Fields!Address.Value,VBCRLF,", "),LEN(Replace(Fields!Address.Value,VBCRLF,", ")-2)
Of course you will need to substitute VBCRLF with whatever linefeed character your database is using.
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.