I have a picture control bound to attachment field. When I begin entering a new record, a random picture is populated in the attachment. My intention is to leave the attachment field without any picture unless a user intentionally uploads the file. I have tried the following code with no luck. Any help here?
Private Sub Form_Current()
With Me.ItemImage
If Not IsNull(.DefaultPicture) Then
.DefaultPicture = ""
End If
End With
'Another try
If Me.NewRecord Then
ItemName.DefaultPicture = ""
End If
End Sub
Study the online-help:
Attachment.DefaultPicture property (Access)
The DefaultPicture property contains (bitmap) or the path and file
name of a bitmap or other type of graphic to be displayed.
Related
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
I am trying to change the font and font size of the text in one box of my form
With Me.[Notes:]
.SetFocus
.FontName = "Verdana"
.FontSize = 8
.ForeColor = vbBlack
End With
I have already looked here
Access VBA programmatically setting font/size not working
And seem to have that working, though I still have a couple of issues.
It changes the text in the right box but on EVERY one of my records, rather than just the one I'm editing.
It only works on text which has been types into the text box directly. Not on text that has been pasted into the form. (This is the reason for the button in the first place)
In case it matters, I'm using MS Access 2016
Thanks in advance,
Daniel
If it's not a continuous form, sounds like you need to add an IF statement to specify under which conditions this should take place. Then place it on the current event of the form.
Private Sub Form_Current()
if condition met then
With Me.[Notes:]
.SetFocus
.FontName = "Verdana"
.FontSize = 8
.ForeColor = vbBlack
End With
end if
end sub
For the second issue you can set the code (or create a procedure and call it) on the afterupdate event of the field
Private Sub notes_AfterUpdate()
if condition met then
With Me.[Notes:]
.SetFocus
.FontName = "Verdana"
.FontSize = 8
.ForeColor = vbBlack
End With
end if
End Sub
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!
I am trying to make the caption of a button the content of a field from a table.
Everything I am finding online in forums and MS websites only shows using a macro with the OnClick. I need it to display without every clicking. It also needs to dynamically change every time the field from the table changes.
How can I achieve this? Again, I don't want an event such as OnClick, I want it to simply read as the field from the table reads.
You could simply use the Form's OnCurrent event to set the buttons caption.
On Current:
Private Sub Form_Current()
If Nz(Me.FieldName, "") <> "" Then
Me.btnTest.Caption = Me.FieldName
Else
'Handle blank record here
End If
End Sub
This will make it so ever time the selected record changes the button will update. Also just add the code into the specific field's AfterUpdate event so it changes then as well.
After Update:
Private Sub Textbox1_AfterUpdate()
If Nz(Me.FieldName, "") <> "" Then
Me.btnTest.Caption = Me.FieldName
Else
'Handle blank record here
End If
End Sub
I'm a newbie to VBA, and will try to make my question clear. I want to add another If Else statement to say when the button OR is clicked, it should to certain stuff else other. So my question is do I have to code anything within Private Sub OR_Click() ... End Sub first then reference it in my new If Else statement?
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
If Filter Is Nothing Then
Set Filter = XFormToFilter.FilterBuilder
Filter.SetPrimaryFilter PrimaryFilter, primaryTable, primaryKey
End If
'This is where I want the button to go
Filter.AddSubFilter "Filter" & .fields("ID"), _
filterString, targetTable, subformDict(targetTable)
.MoveNext
Loop
End If
Thanks a bunch!
You should have created a toggle button in the form designer (not a standard button). Every control has a generic Name which Access will set unless you change it -- something like ToggleButton115. You can then write code within the filter handler like this:
If ToggleButton15 Then
'OR option has been set; change the filter appropriately
Else
'OR option has not been set
End If
NB: This works because the togglebutton's Value property is True or False depending on whether it has been toggled or not. The Value property is the default property -- the property VBA assumes you want to use when you don't specify a property on an object.
See here for more details.