How to perform font changes to a report using an option box - ms-access

I am having issues trying to use an option box to change a font on a series of controls. Basically, I have a report (named Q_tblProject52Week) embedded in a form. I have embedded an option box within the form (called "cornice33) which aims to change the font on the two controls (testo107 and testo108) embedded in the report.
At the moment I am trying the following with no success:
If Cornice33 = 1 Then
testo107.FontName = "calibri"
testo108.FontName = "times"
ElseIf Cornice33 = 2 Then
testo107.FontName = "times"
testo108.FontName = "calibri"
End If
I am getting a missing object message (it is not recognising the controls testo107 and testo108). Also important to note, the report is embedded in a folder control.

You need to tell access that you refer to a control on the report which is a child of your form.
If Cornice33 = 1 Then
Me.Q_tblProject52Week.testo107.FontName = "calibri"
Me.Q_tblProject52Week.testo108.FontName = "times"
ElseIf Cornice33 = 2 Then
Me.Q_tblProject52Week.testo107.FontName = "times"
Me.Q_tblProject52Week.testo108.FontName = "calibri"
End If
hope this helps

Related

VBA - Filling input boxes in Internet Explorer not working

I'm having the following problem which is once I populate some inputbox on IE with information from Excel using VBA, these are populated correctly but when i change onto the second line with input boxes (they all are the same in format) the one I filled before does not get saved (even if I press save).. the only way I found for the information to remain is if I get into any of these boxes I'm filling and type something manually.
Anyone has an idea of why this might be?
Thanks!
For Each cell In wsbd.range(range("A6"), range("A6").End(xlDown))
additemsbtn.Click
Set aNodeList = ieDoc.querySelectorAll("[dojoinsertionindex]")
aNodeList.Item(0).Click
For i = 0 To 15
If ieDoc.getElementById("meetingResultsPlanningTable").getElementsByTagName("select")(0).Item(i).innerText = wsbd.range("A6").Value Then
ieDoc.getElementById("meetingResultsPlanningTable").getElementsByTagName("select")(0).Item(i).Selected = True
Exit For
End If
Next i
Set dropOptions = ieDoc.getElementById("meetingResultsPlanningTable").getElementsByTagName("select")(5)
dropOptions.Value = "Value"
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("InputBox")(0)
itemName.Value = wsbd.range("F6").Value
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox2")(0)
itemName.Value = wsbd.range("J6").Value
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox")(0)
itemName.Value = wsbd.range("Q6").Value
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox")(1)
itemName.Value = wsbd.range("T6").Value * 100
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("NumInputBox")(1)
itemName.Value = itemName.Value + 0
'Set savebtn = ieDoc.getElementById("/images/buttons/save.gif")
' savebtn.Click
Next cell
The code is working and is reading properly all the inofrmation in Excel, finding the corresponding Input boxes and populating them but then nothing gets saved or recorded.. as you can see I tried saving after completing the boxes but it still doesn't work...
I came up with a solution! And pretty simple by the way.. I just added a fireevent ("onchange") for each input box and that records all changes!
Set itemName = ieDoc.getElementById("dynamicLineItems").getElementsByClassName("InputBox")(0)
itemName.Focus
itemName.FireEvent ("onchange")
itemName.Value = somevalue.Value

How to make global changes to Access forms?

I've inherited a database which has a tabbed form, which in turn has tabbed subforms. Many of the subforms have a label that has to be corrected. If this were a Word document or Excel workbook, I'd use Find-and-Replace-All. You can't do that across controls on forms, can you?
Is there a way to do so using VBA? I think it would look something like:
Set aForm = Me
For each aPage in aForm.Pages
For each aControl in aPage.Controls
if aControl.type = "Label" then
if aControl.Value = "OldText" then aControl.Value = "NewText"
end if
Next aControl
Next aPage
EDIT -------------
I tried this code:
For Each aForm In Application.CurrentProject.AllForms
For Each aPage In aForm.Pages '<---- Error here
For Each aControl In aPage.Controls
If aControl.Type = "Label" Then
If aControl.Value = "OldText" Then aControl.Value = "NewText"
End If
Next aControl
Next aPage
Next aForm
But I get an error where I put that arrow. It says "Object doesn't support this property or method", which means it doesn't like "aForm.Pages". What's the right way to cycle through tabbed pages?

How do you update a selected dropdown value using VBScript

I am trying to problematically change the dropdown selection on an InternetExplorer.Application then save that selection. The code I have so far is
dim myValue
myValue="3"
for j = 0 to obj.Options.length - 1
if(obj.Options(j).Value = myValue) then
obj.Options(j).selected = true
exit for
end if
next
This works on the current pages dropdown list, however when I click save, the value "3" isn't saved and it reverts back to its original value when I reload the page.
Another thing to mention is that when I manually click the dropdown and select a value then save, it does update to the new value when I reload the page. I have tried the obj.click function on it but I do not believe a programmatic mouse click works like a actual mouse click with the action listener.
My guess would be something to do with the databinding between the new value selection and the action listener for the page. I am fairly new to vbscript and have tried all sorts of different things.
Any help would be very much appreciated. Thank You!
Supposing you have the obj object set properly, e.g. something like
set obj = ie.document.getElementById("my_dropdown") then you should ensure that only one option is selected:
for j = 0 to obj.Options.length - 1
if (obj.Options(j).Value = myValue) then
obj.Options(j).selected = true ''' do not exit for
else
obj.Options(j).selected = false
end if
next
or
For Each opt In obj.Options
If opt.Value = myValue Then
opt.Selected = True
Else
opt.Selected = False
End If
Next
Caution: above code snippet could result to (undesired?) case that no option remains selected!

Hide Detail Field Depending other variable in Access Report View (Not Print View)

I have a tabbed control (TabCtl45) in the "Detail" section of my report that that has three tabs. (Page1, Page2, Page3). I only want to show one page depending on another variable known as Fee Type. If FeeType = 1, then Page1 tab shows. If FeeType = 2, then page Page2 tab shows... etc.
I was able to make this work in "Print View" with the OnFormat event; however, I want all my data in one easy flowing page like report view. Not in separate pages like print view outputs.
The code looked like this:
If Me.FeeType = "1" Then
Me.TabCtl45.Pages("Page1").Visible = True
Me.TabCtl45.Pages("Page2").Visible = False
Me.TabCtl45.Pages("Page3").Visible = False
ElseIf Me.FeeType = "2" Then
Me.TabCtl45.Pages("Page1").Visible = False
Me.TabCtl45.Pages("Page2").Visible = True
Me.TabCtl45.Pages("Page3").Visible = False
ElseIf Me.FeeType = "3" Then
Me.TabCtl45.Pages("Page1").Visible = False
Me.TabCtl45.Pages("Page2").Visible = False
Me.TabCtl45.Pages("Page3").Visible = True
End If
How do you I get this code to work in report view from the "Detail" section of my report? There is no event that I can see working for this purpose in the properties "Detail" section.
You can't. The Report View is rather limited, the section events (like Detail.OnFormat) simply don't run in this view. Only in Print/Print Preview.
The only thing you can do to format single records in Report View is Conditional Formatting, but that's no use to hide things.
On an unrelated note, you can simplify your code a lot by doing:
Me.TabCtl45.Pages("Page1").Visible = (Me.FeeType = "1")
Me.TabCtl45.Pages("Page2").Visible = (Me.FeeType = "2")
Me.TabCtl45.Pages("Page3").Visible = (Me.FeeType = "3")

MS Access vba programmatically accessing and setting label properties

Is it possible to access labels programmatically with VBA. I'd like to create a number of labels using a for loop such as that shown below which would set all labels named "Label1" to "Label20" to visible
for a_counter = 1 to 20
Me.Label(a_counter).Visible = True
next a_counter
Is something such as the above possible?
You can refer to each of those label controls, "Label1" thru "Label20", by name from the form's Controls collection.
For a_counter = 1 To 20
Me.Controls("Label" & a_counter).Visible = True
Next a_counter
labels are a specific kind of controls in access forms. You should be able to write down some code like this:
function listLabels()
dim m_ctl as control
for each m_ctl in screen.activeForm.controls
if m_ctl.type = .... 'please check the control types available!
debug.print m_ctl.name
end if
next m_ctl
end function
Be careful. I am not even sure of the control's properties (.type, .name) but you will easily find them in the help. Look for 'control' object.