Input box in MS Access 2016 Reports - excel

I am new to MS Access. I have created a report which pulls data from excel and displays on the MS Access form output. I have added a text box for which in Properties->Control Source I added "PO#" as in fig 1.
So the user enters the value in the dialog box when he tries to open the report as below in fig 2. I need to add a default value in the dialog box in the format "LDXXXX" where XXXX is the financial year. I have the logic to generate the financial year as below:
If month <= 8 then
Current year
else
current year + 1
I don't know where to implement it. The dialog box should have the above format as default value when the user tries to open the form and it should populate in the text-box from fig 1. I know there are three events that can be accessed when we click on the text and go to "build events"-Macro, code or expression builder but how to implement this for the dialog box?

If PO# doesn't exist in the source data, it probably shouldn't be referenced as a control source. Does the user need to change the LDXXXX default, or did you implement this to ensure the value is being populated? If the latter, you could probably just use something like this as the control source of the texbox:
="LD" & IIf(Month(Date())<8,Year(Date()),Year(Date())+1)
And if the user needs to change it, keep the txtbox called 'PO#' and add code to the load event of the report.
Private Sub Report_Load()
Me.[PO#] = InputBox("Fiscal Year:", "Fiscal year", "LD" & IIf(Month(Date) < 8, Year(Date), Year(Date) + 1))
End Sub

Related

Excel VBA Data Validation Dropdown, current highlighted item

Short question:
Is there any way to tell which item is highlighted in a Data Validation cell drop down?
Details:
I'm trying to make a tooltip (using a form that follows the mouse when that cell is moused over; will have to change this to cover the dropdown area as well) that gives more information based on the current selection.
I want to do this for the current highlighted item in the list, so that the user can get more info without having to select the item then start over if it's not the one they want.
I also am trying to avoid using the Form Controls & ActiveX Controls. That's more by request from the person in charge than my decision.

Is there a way to check if a labelbox has been updated in a manner similar to TextBox_AfterUpdate?

I am making a userform that will allow a user to click on a date in a calendar and update a labelbox on the form with the date (see image attached). I would like to write a code that will check/ensure that the "Week Start" date is always on a Monday, and if not, an error will be displayed and those labels will be cleared.
I have an "Enter" button where I've already coded what I want (see below), but would like to have the error automatically display when the user clicks the wrong date on the calendar.
If there is a way to do this in a manner similar to the TextBox AfterUpdate event, I would be greatly appreciative.
'Error message stored in Enter button if work week is selected that does
'not start on a Monday
If Not Format(datFirstDay, "w") = "2" Then
MsgBox ("Please select a work week that starts on Monday.")
lblStartDate.Caption = ""
lblStopDate.Caption = ""
LengthNo.Caption = ""
End If
Image of what the form looks like.
It looks like the user is selecting the date from the calendar and you are just using the label to display the selected date. It would be helpful to show the code that sets the value of the label. You should associate your error checking with entering the date on the calendar rather than any event related to the label. Talking about events on the label is a red herring.

Spin button for showing Month by Month on Chart Graph

So i have the template layout in the picture attached below. I would like to know how to link the Spin button to able to show month by month when i click on the spin button.
Here is the formula i have so far, everything working fine except for the chart doesn't connect to the spin.
E4 formula : ="Monthly "&E5&" - Audit Sheet Delivery"
data for eat month for LATE row:=IFERROR(VLOOKUP(G3,$A$4:$C$6000,2,FALSE)," ")
Same for On-Time:=IFERROR(VLOOKUP(G3,$A$4:$C$6000,3,FALSE)," ")
Spin button link to cell $E$5
I have created define name for each Month, Late and On-Time and linked it to the chart but it doesn't work.
Please point out what i have to do in this case. Also, please show the code on here due to i am new to this. Thanks
Thanks you all for your help. I did figure out one way to make it work for me. However, i will more than happy to learn new way or a better way to use spin button and scroll button to changing my chart.
Changes data layout table
Using index formula and vlookup (Cell F19, G19,H19) formula included in picture below)
Changes define name formula to pull data from Cell (Cell F19, G19,H19).
Now i can click on my spin button and the chart changing month by month for me.
It is working fine for me. But i love to learn more if anyone can show me a better way to do it. Please include pictures and formula in your answer. It will help me and other easy to follow it. Thanks
How to do anything anything Excel can do, but with VBA code:
Virtually anything you can do manually in Excel (ie, via the ribbons/toolbars) has an equivalent in VBA.
If you are unsure of which VBA method or property to use, you can turn on the macro recorder and manually perform the action. The macro recorder translates your actions into Visual Basic code. After you record your actions, you can modify the code to do exactly what you want.
There are some limitations to recording macros, so if needed, certain actions have to be added after recording, such as conditional branches (eg., IF statements), variables usage loops, error handling, and text selections made with the mouse (however keyboard combinations do record).
Record an action:
For example, if you want to automate the process of saving the file with a new name, but you don't know which property or method to use, you could do this:
On the Developer ribbon, click
Change the default macro name to a name of your choice and click OK to start the recorder.
Hit F12 to open the Save As... dialog and save the file with a new name.
On the Developer ribbon, click
On the Developer ribbon, click Macros.
Select the macro name that you assigned (in Step 2) and click to view the VBA code within.
See the tips & resources at the links below to help get you started with automatizing Excel (and other Office applications) using VBA code.
More information:
Office.com : Assign a macro to a Form or a Control button
MSDN : Getting Started with VBA in Office
MSDN : Recording a Macro to Generate VBA Code)
MSDN : Revising Recorded VBA Macros
homeandlearn.org : Excel VBA For Complete Beginners
Stack Overflow : Overview of Form Controls and ActiveX Controls
Original Post:
How to filter a chart
The ability to filter a chart by month is built-in to Excel. After you create a chart, you can change the data series in two ways:
Use chart filters to show or hide data in your chart, or,
Use the Select Data Source dialog box to edit the data in your series or rearrange them on your chart.
Filter data in your chart
Click anywhere in your chart.
Click the Chart Filters button next to the chart.
On the Values tab, check or uncheck the series or categories you want to show or hide.
Click Apply.
If you want to edit or rearrange the data in your series, click Select Data, and then follow steps 2-4 in the next section.
Once you know how to use the filters, you can record a macro while filtering as required, an use the code for buttons or other controls.
More Information:
Office.com : Change the data series in a chart
MSDN : Recording a Macro to Generate Code
MSDN : Revising Recorded Visual Basic Macros
Steps
This is broadly similar to yours. Below is just meant to show you how to use dynamic named ranges as chart series sources. If you later decide to specify start and end ranges of months, you could use this same model and have the start and end indexes generate the height argument for Offset thus being able to plot ranges (though they would be aggregate).
Using the same data layout as in your answer.
① Add a forms control spin button, assign its linked cell as K3, then put the font to white so it is not visible. Its values run from 1-12 with increment 1.
② I then create two dynamic ranges:
LATE with formula =OFFSET(Sheet1!$G$4,Sheet1!$K$3-1,0,1,1)
OnTime with formula =OFFSET(Sheet1!$H$4,Sheet1!$K$3-1,0,1,1)
You can add these via name manager (Alt+F3)
Name manager:
③ I then insert a bar chart and add two series which use these dynamic named ranges as their source:
The above is for Late and this is repeated for OnTime. Note that the workbook name goes before the reference to the dynamic range.
④ In J2 I enter the chart title text "Monthly - 5 KPI Delivery" and point the chart title at this with = J2 in formula bar whilst chart title is selected on the chart.
⑤ K2 has the formula =INDEX(F4:F15,K3) and is used to retrieve the Month name from the list of months via Index with row argument the linked cell value from the spin button.
I then edit the chart X axis source with formula =Sheet1!$K$2 so the month name appears on the bottom of the chart.
⑥ Finally, any other chart sprucing you like. I chose to group and lock the chart and spin button together so they will move as a unit and to ensure data point values where shown.
Final result:
In action:

vba and outputing data from hidden/Non-enabled multipages

I have a userform with various tabs on a multipage. I am using datepickers (Microsoft Date and Time Picker Control 6.0) and textboxes on the different tabs.
The problem occurs when I want to get the data from the hidden, non-enabled or simply non-active multipages to output to the worksheet.
For example, Multipage1 has a Date of Birth, Multipage 2 has a start date.
When I press the command button to execute the output of ALL data across all multipages to the worksheet, it will only output the value for the currently active multipage. The other values are default.
Mulitpage1 active means it will return D.O.B but returns a blank/default start date from Multipage2
Multipage2 active means it will return start date but returns a blank/default D.O.B from Multipage1
Multipage 3 active means neither D.O.B or Start Date will output anything other than their default values.
(Presume all fields across all multipages have actually been completed with a value)
Is there a way around this?
The command button to output data has a long list of statements like these:
Cells(6, 2) = Address1TextBox.Value
Cells(7, 2) = Address2TextBox.Value
Cells(8, 2) = Address3TextBox.Value
DatePicker was the issue here and I know textboxes do not have an issue with being output to the worksheet while hidden/disabled.
With this in mind I had to resort to using a textbox with validation which only allows the user to enter a date.
Answer = Don't use Microsoft Date and Time Picker Control 6.0

excel spreadsheet data to web form

I'm looking to place my company's trailer inventory on a few free classified ad sites. Our inventory database (filemaker) can export data into an excel spreadsheet (column A-Make, B-Model, C-Year, etc.) including the URLs of the photos of each trailer.
Our dealer sites allow for bulk uploading through XML and that works great.
My problem is on the smaller free classified ad sites that have a web form that needs filled out (the example I'm using here has text fields and drop-down menus, but other sites have check boxes and radio buttons) then submitted for each individual trailer (about 90 trailers). I'm wondering how I can use the data in my spreadsheet to auto-fill the form with the information in row 1, submit it, re-navigate back to the form and repeat the process with the info in row 2 and so on. I know that I'm going to have to tailor my data and columns to fit each site (match column names to field names and change relevant data to match drop down options, etc.).
**edit Also (although not necessary) it would be nice if it was possible to have my photo URLs entered as well (if at all possible).
I've created a "test" account on http://www.horseclicks.com. Once logged in you have to click on "My Trailers" on the left and then the "add" button
user: excelhelp
pass: excel
Any takers??
This doesn't completely answer your question, but would save you some time entering the forms manually. If you know the names of input tags on the form you want to fill out, you can write a Javascript that will fill out the form for you: i.e., document.getElementById('your_name').value=Name[x]; etc.
In that example, Name would be an array that would contain a list of the names you wanted to put in the input field "your_name". You can easily turn an Excel sheet into a Javascript array by exporting to CSV and cut/paste into your code. Make it so that the value of x increases by 1 each time the script is ran.
Take your whole javascript, and turn it into one line that starts with "javascript:" and place this as a bookmark in your toolbar. Now you can go to the form, hit the your bookmark button and it will fill out the form. Hit submit, go back to the form, hit the button again...

Resources