MS Access 2007 add logo to all forms - vba

I am wanting to add a logo to all my forms/reports etc. I want to either store the image once in the database, even in the front end is okay, or I want to access a picture on the network/local computer. I really don't care. I can store a location in a table, and use a dlookup call as the control source in a picture control, and it works, but there is a noticeable delay from when the form opens and when the picture actually appears. If I paste the picture in to every place, it works great! But if I want to change the logo, I must open all my forms/reports and change every single one.... there has to be a faster way to change out my logo pictures and still get them to load instantaneously. Can you help?

You could use vba perhaps. Create a global variable in a module to link to a file location. You could then use an image control on each form and set the source to the file location stored in your variable on the open event.. That way you would only ever change the value of the global.
Your code might look like this in each form:-
Private Sub Form_Open(Cancel As Integer)
Image0.Picture = yourGlobalFileLocationVariable
End Sub

Related

Search form doesn't work on front end database

I split a database and created a search form in the front end. It works there, but when I copy the front end, the search form doesn't work there
The form is a continuous form and has my table as a datasource. There are a number of bound fields in the detail section and a number of unbound fields in the form header. On the click of the search button, I use vba to build a sql select string and use Me.RecordSource = strSQL. Again this works in my original front end db. After realizing it doesn't work in a copy, I have tried copying and pasting the form from one front end to another, export/import, recreating it, hard coding a select, trying to display a message box on the click...nothing seems to work on the button click (tried double click too). If I build a button with the wizard, it will work, but they are using built in macros.
Any thoughts? Thank you in advance.
If no code seems to run in your new database (including MsgBox), then it is quite likely that the new database is in a folder that Access doesn't recognize as "trustworthy" and has therefore turned off code running.
Check that the folder where the database is currently located is allowed to run code, and if not add the folder:
File|Options|Trust Center|Trust Center Settings|Trusted Locations
Regards,

VBA to generate a default file name when Save As is selected in Word 2016

I have VBA that, in Word 2010, will default a file name into the Save As screen when the user selects the Save As file option. Word 2016 (Office 365) has a different interface with a screen to select a save location (OneDrive, This PC,etc) prior to the "standard" Save As dialog box appearing which seems to have broken the code to generate a specified default file name.
The code (with title simplified) is
Sub FileSaveAs()
With Dialogs(wdDialogFileSaveAs)
.Name = "MyTitle"
.Show
End With
End Sub
If I run the code in Developer to Debug, it works fine, with the Save As screen appearing and the file name defaulting but it does not work in the live environment where the file name defaults to the previous document name.
Based on web research, I have tried additional code to change the properties of the document place the name in the title as this is supposed to then default when Save As is selected but that also doesn't work.
Any suggestions or recommendations on how to resolve this would be appreciated.
Thanks!
Update 1/11/16:
Have been able to get a little closer by using the following:
Application.DocumentBeforeSave Event
example here https://msdn.microsoft.com/en-us/library/office/ff838299.aspx
tied to Using Events with Application Object
example here https://msdn.microsoft.com/en-us/library/office/ff821218.aspx
Had to add
Cancel=True
to the end of the event procedure code or the Save as Dialog box will open twice.
Still a bit clunky and seems to be limited to run only before the first user generated save event but almost workable.
Wanted to share what I found in case it helps others but any other suggestions for improvement would be appreciated as it still doesn't seem like the best solution.
Thanks again!
Thanks for reporting this. I have a potential workaround that I hope will help.
Could you use the SendKeys method (https://msdn.microsoft.com/en-us/library/office/gg278655.aspx) to send the keyboard shortcut (F12 for the Save As dialog, full list: http://aka.ms/Tf6yv0) to the application e.g.
App.SendKeys("{F12}")
when you need the Save As dialog to be displayed?
I hope this helps. Thanks again for bringing this issue to our attention, we will be looking further into the root cause.

Excel: Fixed Button Position

Needing some help attaching an Excel/VBA button on an Excel sheet. I need it to stay in the same position on the screen regardless of how I scroll or zoom. Preferably, I need this on the bottom left or right of the screen.
I have tried adding a button. Then, I right clicked on the button. Clicked on Format Controls -> Properties -> selected Don't Move or Size With Cells. Am I missing something that's making this not work?
Thanks!
I know this post is old, but here's to anyone it could be useful. The VisibleRange property of ActiveWindow can solve this problem. Use something like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet.OLEObjects("MY_BUTTON'S_NAME")
.Top = ActiveWindow.VisibleRange.Top + ActiveWindow.VisibleRange.Height - 5
.Left = ActiveWindow.VisibleRange.Left + ActiveWindow.VisibleRange.Width - .Width - 5
End With
End Sub
Here is the idea that I put across the comment earlier today :) Typically we can get a Floating User Form by setting the Modal property of the form to be 0 which is indeed a Modeless state.
Basic Points to consider:
Look & Feel of the form to make it look like a Button (Not show title bar/Not Resizable/
Hidden Close Button etc)
Setting the position of the Button
Which Event should trigger the form-button (WorkBook Open)
What would you do with Form Initialize Event
Whcih Events should keep it stick to the same position alive
Further Points to consider:
You might only want to keep this button vissible for the workbook you are working, and if you open another instance of a workbook, do you still want to keep the button
If you minimize the Excel Window instance, how do you plan to manage the state of the button and keep it visible
Post about keep displaying a form even the workbook is minimized.
One other great reference I happend to see, (little bit technical) but worth the shot - at least to get to know the certain properties/methods that you could make use: Extending VBA User Form Control.
The article include the following info, and please note the last line as well :)
They give you access to capabilities that are not available from VBA or from the objects (UserForms, Workbooks, etc.,) that make up a VBA Project. When you call an API, you are bypassing VBA and calling directly upon Windows. This means that you do not get the safety mechanisms such as type checking that VBA normally provides. If you pass an invalid value to an API or (a very common mistake) use a ByRef parameter instead of a ByVal parameter, you will most likely completely and immediately crash Excel and you will lose all your unsaved work. I recommend that until you are confident that your API calls are solid you save your work before calling an API function.
Add new Row on the beginning of your WorkSheet and set your button on it, then:
Freeze Top Row
Right click → properties → placement → change to 3.

vb.net add text to form without interaction

I have a winform project which lists all the files in a specified folder. It allows the user to select a new destination for each file, and when the user has chosen the destinations for all files that he would like to be moved, it moves the files, one by one.
My next step is, I need to display a confirm form when the files are being moved, and add each file's name and destination to the confirm form as it is being moved.
My question is:
How can I add more text to the confirm form's controls after I already loaded it (using confirm.showdialog() from my other form, without any user interaction? I imagine that I need to do it from the original form, because it needs to display each one when it starts to move that file, but I'm open to any suggestions:)
TIA
Both above answers are good.
If I understand correctly, your main form will allow one to select multiple files, then select their destination and launch the move process. If that's what you need, I would simply do the following:
Create a new form that would report the process to the user, without requiring any interaction, but just to inform the user what file is being moved;
Create an instance of a BackgroundWorker object, and call the file-move method from the BackgroundWorker.DoWork() method (within your main form);
Flag your BackgroundWorker to report progress, then call the BackgroundWorker.ReportProgress() event handler from within your move-file method;
Use the previously created list of file names to get its name and report it to your file-move dialog form while the file is being changed. A simple DataBinding over a Label should do the trick while you'll move your CurrencyManager to the next item within the list, or you could simpler use the list indexer to get the filename at a particular index;
When the user launches the move process, get your filenames and and count them, then set your ProgressBar Maximum value to the number of files you have.
The BackgroundWorker.ReportProgress() method takes an integer value as its argument, then, with your ProgressChanged() event handler, you will be able to display the name of the file being copied to your window by getting the filename at the index location, index given by your ReportProgress() method.
This will allow you to use the performance of a supplemental thread, without "freezing" your main thread from which your form has been created, then you will be able to simultaneously perform your file move, and display the filename to the progress-form, while illustrating to your user visually what the progress is about through your ProgressBar control, and displaying the filename as required.
Does this help?
Wouldn't it be simpler to make another form instead of using preset dialogs?
that way you can just have a textbox that you populate and refresh
You could do put all of the code to show the moving of the files inside the confirm dialog window.
But to give a more complete solution could you tell me how you are gathering the file moving information.
A Good solution would be to just pass in the list of the files to be moved and then perform the moving function in the dialog.

VBA Status Bar

I am working on a Word VBA macro app for 80 or so users. The office has high staff turnover, so training suffers, and so one of the self imposed requirements for this project is comprehensive, friendly documentation. However, to supplement this, and to save newbies having to open up a 100 page document when they want to try something new, I want a status bar on every userform (there are five) that provides contextual help. I find tooltips annoying.
I don't have a lot of experience, so I was wanting to
Essentially, I have a file containing every status string. (This is currently a text file, but I was wondering if I should use a spreadsheet or csv for ease of editing by other staff in future.) Every control has a MouseMove event which refers to a function: getStatus(cID) that opens the file, grabs the line and displays it in the status label. It also grabs a few parameters from the same line in the file, such as whether the label is clickable (to link to a page in the help file), and what colour the label should be.
So a few questions really:
Will the application be slow if a userform is constantly referring to a file? It feels fine to me, but I've been in it far too long, and I'm the only user accessing that file. There will be 80 constantly accessing it.
Is MouseMove over a control the best way? Should I instead use co-ordinates?
Most importantly (in terms of me having to do as little work as possible) is there some way to do this so that I do not have to have a MouseMove event on every single control? I have a good few hundred or so controls, each with their own identifier (well, not yet, but they will if this is the only way to do it). Maybe when the form loads I could load ALL the possible status lines so they're ready for whenever the control is moused over. But then, maybe the loading time is negligible?
Appreciate any ideas or thoughts - especially if VBA already has a whole range of functions to do this already and I'm just trying to reinvent the wheel. I can't use the application status bar, because the user rarely sees the application itself.
Thanks!
EDIT:
It is for both data entry, clicking around and a bit of document generation.
It is a controlled environment so macro security issues aren't a big concern for me - and if something goes wrong it's someone else's fault or problem :)
Is this data entry app or do they just click stuff? Because often the field with focus is different to the item the mouse is hovering over, this can cause a lot of confusion.
Constantly reading from a file is a huge waste of time and resources - it is much better to load them only once into an array or collection when the form is loaded.
On MouseMouse event is better than coordinates because you can move things around without worrying. It's a lot of code but you should be able to generate most of that if you have a list of control names because the code should be identical.
ie
Sub Control_MouseMove()
DisplayStatus(Control)
End sub
I would consider the StatusText property and ControlTipText property of controls for this kind of help.
StatusText
This example sets the status bar help text for the form field named "Age."
With ActiveDocument.FormFields("Age")
.OwnStatus = True
.StatusText = "Type your current age."
End With
ControlTipText
This can be assigned from the property sheet for the control.
Private Sub UserForm_Initialize()
MultiPage1.Page1.ControlTipText = "Here in page 1"
MultiPage1.Page2.ControlTipText = "Now in page 2"
CommandButton1.ControlTipText = "And now here's"
CommandButton2.ControlTipText = "a tip from"
CommandButton3.ControlTipText = "your controls!"
End Sub