Prev: Custom Record Selector Controls that don't work like the built-in ones
Next: Custom Record Selector Controls that don't work like the built-in ones
From: BruceM via AccessMonster.com on 25 May 2010 07:44 As I said in a previous posting, you can get the path to the database folder with CurrentProject.Path. It may go something like this in the form's Current event, assuming an image control named imgMain: Dim strFile as String, strPath As String strFile = "MyFile.jpg" strPath = CurrentProject.Path & "\Images\" & strFile Debug.Print strPath Me.imgMain.PictureType = 1 ' Linked Me.imgMain.Picture = strPath I don't know where the file name is coming from. It may be that you can use the InStrRev function together with the Right function to extract the file name from the end of a string that consists of the full path, whether you use the Insert Hyperlink dialog to insert the link or generate the file name by other means that include the path. I'm not completely certain whether the PictureType line of code is needed. It does no harm, in any case. Assuming you are using a command button to add the link, you will need the same code in its Click event, with the addition of: Me.Refresh I can't tell if you are familiar with the use of the Immdiate code window. When you run code, Debug.Print causes whatever you specify (strPath in this case) to be written to the immediate code window, which you can view after running the code (in the case of the Current event, after you have arrived at a record) by pressing Ctrl + G. You can also go to the immediate window at any time to test code. To see CurrentProject.Path, in the immediate window: ?CurrentProject.Path To see the database name: ?CurrentDB.Name To see the current date and time: ?Now() And so forth. Note that the question mark is needed. Also, the above are system-wide functions, so you can find their values in the immediate window. The current path applies no matter where you are in the database, so you can test their values at any time. Same for global variables, although it is usually better to avoid those if you can. Note that you cannot use the immediate window in this way to find the value of a control or of a variable that is generated within a procedure, as there is no context. However, if you place a break point into a procedure you can test values located within the procedure. For instance, if you place a break point in the code above, when the code breaks you can type in the immediate window: ?strPath and you will see the value of strPath. However, if the code is not running, there is no context for strPath. John F wrote: >I am storing the database in "My Documents", on the desktop which has >multiple HDs and is on drive D: and on the laptop which has 1 HD it is on >drive C:, this is the only difference in the path name. > >How I am displaying the image is using an “Image Box” with a control source >set to [txtPath] which is the field that stores the path to the image which >looks like D:\users\my name\documents\the database folder\Images\name of >picture.jpg and on the laptop it starts thus C:\users……………. > >> CurrentProject.Path gives the path to the database. If the images folder (I >> will call it Images) is located in the same folder as the database you could >[quoted text clipped - 30 lines] >> >> > >> >> >Thanks in advance -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1 |