Situation: I download Attachments from Outlook and import them into Access tables based on a few criteria.
For example, I download following files: SenderA_A_Timestamp.csv, SenderA_B_Timestamp.csv, SenderB_C_Timestamp.csv, SenderC_A_Timestamp.csv and loads more.
Now I have made a form where the user can, for example, select all type C CSV-Files since a date or just all types, since a certain date.
Cluster, Hosts and Volume represent the File types. The datetime indicates when it was updated last. Cl_Import, Hosts_Import and Volume_Import are the import specification needed for the different files.
Problem: I now want to add a new type, for example, under Volume and want to have it stay there when I open the Form the next time.
Software: -Microsoft Access 2016 -SQL queries -Outlook 2016 -VBA
Create a table called
SwitchboardItems
.Add these fields:
ItemNumber
should be sequential (use AutoNum if you want).ItemText
is the text as it will appear on the form.Command
indicate what to do when the button is pressed.Argument
is anything pertinent to that option (such as the file name to be opened).Create a blank
Continuous
form.The Record Source is:
SELECT * FROM SwitchboardItems WHERE [ItemNumber]>0 ORDER BY [ItemNumber];
ItemNumber 0
is the heading for the menu so is ignored in the record source.Turn
Data Entry
,Allow Additions
,Allow Deletions
,Allow Edits
andAllow Filters
toNo
on theData
tab in the form propertiesAdd a command button and a textbox to the
Detail
section of your form.Give the button the name of
Option1
and the textboxOptionLabel1
.The
Control Source
for the textbox isItemText
.Add a label to the
Form Header
name itLabel1
.Add the below code to the
Form_Open
event. It places the menu heading in the form header:Add this code to the form module:
Each Case statement reflects the
Command
value in theSwitchboardItems
table and you should code what you want each to do (open workbooks, close the database, run SQL, etc).Finally, add this code to the click events for the Option1 textbox and command button:
Your finished form will look similar to this (I've clicked Other_Import button which displays a message box as Command is 2):
NB: There's a lot more you could add to this - the last updated time as an extra field in the table for example.