Available space for forms in msaccess - ms-access

I am trying to find a way to get the dimensions of the space available in ms-access to show forms. The yellow part in the image below
Both height and width would be nice to know but for the moment it is sufficient to get the height to be able to resize forms in the available height.
It depends on the presence of the ribbon and size of windows borders and statusbar. I cannot find any Application properties that show these dimensions.
Is that possible at all?

I think the easiest way is to create a form .
Lets call him Form1 then
add this to load event and open the form
Private Sub Form_Load()
Docmd.RunCommand acCmdAppMaximize ' to maximize access
DoCmd.Maximize ' to maximize the form
Debug.Print Form_Form1.FormHeader.Height 'if exist
Debug.Print Form_Form1.PageHeaderSection.Height 'if exist
Debug.Print Form_Form1.Detail.Height
Debug.Print Form_Form1.PageFooterSection.Height 'if exist
Debug.Print Form_Form1.FormFooter.Height ' if exist
' Total form height is total of the above
Debug.Print Form_Form1.Width
Debug.Print CommandBars("Ribbon").Height ' this is the Ribbon height
End Sub
Hope that help. Important all the values are in points (some Strange units of measure from microsoft , google for points 2 cm or what ever you like ) Ops... the measure values are in TWIPs as june7 commented.

Related

Concatenate Rich Text Fields (HTML) and display result on Access form

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

Dynamically add image controls on Access report

I have a table in Access that has comments in one field and a file path to an associated picture in another. My report has the comment and then an image bound to the file path field underneath that comment. However, most comments do not have a picture with it, and the empty space between comments makes the report unnecessarily long.
Is there a way in VBA to only add an image control if there is a file path and minimize the spacing between the pictureless comments?
You can't add any controls to a report when Access is in Runtime mode. But you can easily resize the image control using VBA in one of the Report's Format methods. Assuming your Image control is named "Image1", and it is in the Detail section:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Image1.ImageHeight = 0 Then
Me.Image1.Height = 144 ' whatever minimum height you want
Me.Detail.Height = 144
Else
Me.Image1.Height = 1440 ' whatever the normal Image1 height is
Me.Detail.Height = 1530 ' whatever maximum detail height you want
Endif
End Sub
That should be very close to what you need.

Access Form Bring Text Box in Front of Listbox?

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.

Referencing the value of a hyperlinked text box

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.

Opposite of combo box .Dropdown method?

Is there a way to toggle the dropdown of a combo box through VBA? .Dropdown is a method and it only works in one direction. I'm looking for the following functionality:
MyCombo.Dropdown = True
MyCombo.Dropdown = False
Obviously the above does not work in MS Access. I'm guessing I'll need to use some sort of hack/workaround for this. I'd like to avoid a .Requery. That would probably work, but there could be a major performance penalty depending on what the source of the combo box is.
I was dealing this this issue today, and after a lot of trial and error, I discovered that the following works beautifully in Access 2010:
With m_cboLookup
.ListWidth = .ListWidth ' Close combo box
'If Len(strSearch) > 3 Then .Dropdown
End With
Essentially, you are just setting the list width to the existing list width, but the combo box is closed, presumably to prepare for redrawing at a different size.
How about setting the focus to another control on the form? That should close the combo box just as if the user had moved the focus somewhere else on the form.
I was just dealing with this as well. The best I could come up with is below. It sends the ALT key twice, which closes the combobox without triggering an Undo or moving focus to another control.
SendKeys "%"
SendKeys "%"
Have you thought about a
SendKeys "{TAB}"
doesn't require you to send focus on any particular control but moves focus off this one
I had tried everything to achieve my desired combo box behavior. I finally found a method that works for me. It's way too elaborate to be the ideal solution, but it works. I tried Adam's listwidth reset method, but it didn't work for me in Access 2013. I had tried the Sendkeys method, but that caused my clients' Num Lock to be turned off. This code gives me perfect combo box behavior.
'The following code goes in a non-class module.
Public booListOpen As Boolean
Public sub subDropDown()
If booListOpen = False Then
Screen.ActiveControl.Dropdown
booListOpen = True
End If
End Sub
'The following code goes in the form module.
Private Sub cboList_Enter()
booListOpen = False
End Sub
Private Sub cboList_Change()
subDropDown
End Sub
Private Sub cboList_Click()
booListOpen = True
End Sub
I know this is an old thread but I had the same problem and tried several solutions. The .ListWidth didn't work for me. It did close the dropdown, but it displayed the bound column values (the IDs) in the 'text box' part of the combobox after the dropdown was closed. Mine is also a multi-select combobox bound to a multi-value field; may be different that the OP.
I was able to solve it by doing .Requery
worked for me.
Combo on worksheet.
SendKeys "{ESC}"
SendKeys "%{Down}"