Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA - Background image positioning

Posted on 2006-07-06
15
Medium Priority
?
660 Views
Last Modified: 2010-08-05
Hello

I want to be able to call an image from my VBA script and have it display on the page. I have some code but I do not know if I am doing it right?

Dim backgrd As String
   
    backgrd = Application_Paths.ScreenBckPth + "\Logon.bmp"

    'Call CreateDesktopShortcut("frmFlash")
   
    Me.imgBack.Picture = backgrd

In order to use the backslash to find the image does it need to be in the same folder? How would I located a file that is in the same file. Within a folder I have my database and also a folder named PNG. Within that folder is a background called "background.png". Does anybody know how to navigate this??
0
Comment
Question by:andyb7901
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
15 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17049777
The folder needs to be in th epath of backgrnd - as long as you can specify the folder and the file and put it into backgrd then it will work.

You can hard code it ie - C:\temp\background.png or you can use a relative location
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17049793
If u want the image to be in the same folder as your mdb

u can use this instead


CurrentProject.Path

to get filename its then

CurrentProject.Path & "\Logon.bmp"


0
 

Author Comment

by:andyb7901
ID: 17049960
Whenever I hard code it I get an error on this line;

Me.imgBack.Picture = backgrd

How would I call the background image to the screen??
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 35

Expert Comment

by:Raynard7
ID: 17050005
Try me.Picture instead of Me.imgBack.Picture
0
 

Author Comment

by:andyb7901
ID: 17050109
that has solved that error, but it tells me object requiremed when I try to find my image through the path.

backgrd = Application_Paths.ScreenBckPth + "C:\Documents and Settings\Andy\Desktop\PraktisIT\PNG\Blank_form.png"

Do you think this is the correect way to do it?
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17050169
This is not the correct way;

You can either do

backgrd = "C:\Documents and Settings\Andy\Desktop\PraktisIT\PNG\Blank_form.png"

or

backgrd = Application.CurrentProject.Path & "\Blank_Form.png"

Depending if you want to set it relative to the location to the db or if the image will always be in the one spot
0
 

Author Comment

by:andyb7901
ID: 17050272
I think it would be sensible to use the bottom piece of code. In case the images and DB are moved. However, would it be possible for me to code it as ..\..\ to come out of the folder and into a new one. Or currently I have a db and a folder named PNG's in the same folder. What I would need is to go into the PNG folder and find an address. Would that be as simple as /PNG/filename.png.
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17050292
It would be as simple addressing \PNG\Filename.png - if the PNG folder is always in the db folder
0
 

Author Comment

by:andyb7901
ID: 17050440
yeah they are. What would be allthe code for the image then?

Dim backgrd As String
   
backgrd = Application_Paths.ScreenBckPth + "\PNG\hEADED PAPER\MainLogoncopy_newlogo"
   
Me.imgBack.Picture = backgrd

Would it be as simple as this?
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17050475
Yes it would be - i would note , it is best if you use & and not + when joining text fields
0
 

Author Comment

by:andyb7901
ID: 17050578
I have done the following but I keep getting the error object required(***). Im pretty sure the path is correct. I placed an image on the page using the irght click and properties command, and then browsing the file. I then copied the files path, and inserted it into my path in my code. So I think it is right?? Any ideas?

Dim backgrd As String

    'on load maxmise this form
    DoCmd.Maximize
   
    ****backgrd = Application_Paths.ScreenBckPth & "\PNG\hEADED PAPER\MainLogon copy_new Logo.png"
   
    Me.Picture = backgrd

    Me.admin.Visible = False
    Me.continue.Visible = False
   
    Me.Picture = backgrd
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 2000 total points
ID: 17050620
This is because you should be using

backgrd =  Application.CurrentProject.Path  & "\PNG\hEADED PAPER\MainLogon copy_new Logo.png"
0
 

Author Comment

by:andyb7901
ID: 17050691
Ah that seems to work now, Thanks!! Do you know why the image is displaying dead centre though. Can the window being opened only be the size of the image? Itsd just that I have spaces in the background image where things like buttons and text boxes need to go?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17051789
andyb7901, I went away to a meeting so I didnt get a chance to help you further on this
But Raynard7 sorted u out
But just wondering, did u not see my post where I mentioned using CurrentProject.Path? though I used logon.bmp as per your example code
0
 

Author Comment

by:andyb7901
ID: 17051894
Im sorry, I did not see your answer. However, Raynard did provide me with a great deal of help, and pointed out other areas to.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question