Modules & VBA :: Display Random Image From Folder (Not Embedded)
Jun 26, 2013
I'm working on a database for my holiday pictures. The pictures are organized in folders per trip/date/location.
When viewing the data of a particular trip, I want the form to display a random image from the respective folder (path stored in database).
I already found a function to count the files in the folder:
Code:
Function GetFileCount(folderspec As String) As Integer
' Returns a count of files in folderspec, or -1 if folder does not exist
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(folderspec) Then
GetFileCount = fso.GetFolder(folderspec).Files.Count
Else
GetFileCount = -1
End If
End Function
I have a form with windows media player embedded in it. What I want it to do is play a random song when I open it. So I put a field called Randomizer in the form and added this code.
Me.randomizer.Value = Int((60 - 1 + 1) * Rnd + 1)
Now How do I put the URL for the song into vba format? I tried just using the URL property field for the player (D:[randomizer].mp3) but no luck.
I have code that automatically send emails out from an Access Customer Contacts Database. I am using Access and Outlook 2007 but the code needs to work with later versions of Access and Outlook.
I have very poor knowledge of coding and usually manage to cobble something together from looking at other code on the net but don't understand most of it.
I have the following code which works perfectly except I want to be able to embed an image in the email body (not have the image as an attachment but actually show it in the body of the email).
Most of the code I have found around this topic is too complex for me to understand and utilise within the context of the code I have.
Ideally I want to take the image from an attachment field in a table returned by the "tblMailingList_Query".
Code: Private Sub Command10_Click() Dim MyDB As Database Dim MyRS As Recordset Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem
Many years ago I created a database that has one embedded image for each project.
I am now redoing this db in 2010 format and I want to extract these images and save them in a folder so I can link them to the new db based on the project ID number
The table is [Project main], the unique project ID is [R&D ID#] and the image file is stored in [Item image] as an OLE object. i would like to save them to C:db images
I thought this would be pretty simple, but I cannot figure out how and wasn't able find the solution here or anyway.
I have a source form. (I can resort to having a Table with OLE Object if I must, but prefer not to.) On this source form I wish to include different things such as company logo. This will determine what logo shows up in all the reports, so all the reports will have an image linking back to this embedded image on the source form.
Pseudo-code Example: frmSource contains imgLogo rptSample contains an image whose control source = Forms!frmSource!imgLogo
How can I do this or achieve the same effect in a more-or-less simple way?
I have a report which is an invoice I have a button on the report to reprint It . Now if this is a duplicate Invoice I need to add a background Image ,something like a duplicate stamp . I have added a message box which says" is this a Duplicate Invoice" .If the answer is yes then I want to display the backgrond image and print the report .If the answer is no, then print report without background image
Public Function DisplayImage(ctlBrowserControl As Control, _ strImagePath As Variant) On Error GoTo Err_DisplayImage Dim strDatabasePath As String Dim intSlashLocation As Integer
[code]...
This works perfectly to display the image I'd like through WebBrowser control I put onto the form....HOWEVER --and here's my question--the image size is not bound to the size bounds of the control size itself.So if my control is 2 inches by 2 inches and the image is 16 inches by 16 inches, then the image doesn't fully show within the control.
I'd like to get the control to show the whole image (sized down as appropiate, or sized up as appropriate) such that the whole image is contained within the control.I know how to limit the display of any image in HTML.
I have some images stored in a SQL Table which is linked into Access. These images have to be stored in the database as I also reference them on other platforms (Android, Web etc).
In my Access programme I need to display a continuous form / report showing each image. Now, good old Access cannot display multiple images stored in the database on a continuous form. It can only do this if it is referencing the path to the image.
When the user views the form they will only see about 12 images at a time. I thought of a workaround which is to write the database images back to file to a local temp directory when the user loads the form. The user would be happy to wait for say 10 to 15 seconds whilst the form loads.
However, I cannot find an efficient algorithm to write the images back to a file. The one I am using is a BinarytoString algorithm by motobit which is fine for very small images, but anything over 100kb (which is still pretty small) it goes sooooo slow.
How to quickly write an image stored as a long binary in an Access DB back to a file? Or do I need to crack open my Visual Studio and write some C# DLL to use instead...?
I have a piece of code that I'm using to display an image on a report based on a path saved to each record. the code is:
Code: Option Compare Database Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) If IsNull(Me.ImagePath) Then Me.ImgPic.Picture = "O:BellinghamIntranetProductionLabelsNo Label.bmp" Else Me.ImgPic.Picture = Me.ImagePath End If End Sub
It seems like every few months the code crashes access and then never works again. When I debug, the part that is highlighted is:
Code: Me.ImgPic.Picture = Me.ImagePath
The only way i've found to correct it is to delete the report and the module and copy them back in from a backup database. What could be causing this code to crash or how to stabalize my database to prevent this from happening again.
random image selection from a form on a buton click event.To be more explicit: i have 7 images on form, when i push one buton i want to see how each image take focus (when take focus .BorderColor =vbRed after lose focus .BorderColor =vbWhite) and after lets say 20s focus stop random on one image and keep that image with .BorderColor =vbRed.
I am trying to link an images (.png) onto a form. I have a folder of all the images I want but I want the path to be relative. So that if I move the access file and the images folder to a new location, it will still work.
In the properties for the image, It works fine as C:UsersjohnDesktopimage1.png but what I am looking for is the ability to use "imagesimage1.png" as the file will always be in that relative folder to the db.
What is the correct syntax for this? putting image1.png in the same directory and just using image1.png works, but this won't be very tidy with 100+ images.
I know from searching it is possible through VBA by getting the root directory of the folder and appending the filename. Don't really want to go this root. I also don't particularly want to create a table to store the images or links.
I'm trying to open a folder based on a BIN nr. This folder could be in a main folder that has diferent subfolder. As there where differnt naming used to create the folderes, one of the things they have always is the BIN nr. It alwasy start with a unique number and maybe I could use it to scan the subfolders and open that one that the BIN nr is equal as in the field BIN.
Now we have serveral 1000th of folders and finding them takes time.
I have a form that I would like to update a picture on using VBA. The source of the picture path is in part a query that is not bound to the form. So far I have the following code that is pretty much working, but with a couple flaws.
Code: Private Sub Form_Current() LoadDefaultPicture End Sub Sub LoadDefaultPicture() Dim db As DAO.Database
[Code] ....
This is working. However, when I change the record the picture flashes the current picture once and then loads the new picture. It is like it reloads the current picture then loads the new one. I'm hoping there is a way to get rid of the flash.
Also, the code fails here: strDefaultPictureName = rs.Fields("AttachmentName")
When the query does not return a record. I can definitely fix this by adding an if statement to check for a record, but I'm kind of perplexed at why it is failing at that line. I would expect it to assign an empty string to that variable name and then fail on the next command where I try and set the ".Picture" property of the image.
i've looked but can't find the answer!! which is unusual as this forum covers everything. i have a field [photo location] with a hyperlink to a folder within which is a number of images. at the moment i have 2500 folders and its growing daily. the action i want when the 'photo location' field had got focus or when clicked is for the photos within the folder to open [not within the form itself] - either in seperate windows or preferably all together. i am using irfanview to display the images but am easy on this point. i do not want to give each photo its own hyperlink because there are thousands of them. any suggestions as to how i should do this?
I have developed a form which contains a subform. The subform contains a bound image for display. Think of a 'department' form with 'employee' records on the subform containing an employee photo. (Very standard stuff.) It used to work correctly but I must have inadvertantly changed something but cant find it.
The problem is that the photos don't display at all as I move through the department records - using the main form's navigation. I need to use the subform navigation to show any of the photos. When I get a photo to show for a particular department then I can navigate through all the employees in that department and their photos display correctly. (If I run the subform separately then the photos display correctly too.)
I want to make a form or report that acts similar to a "bookshelf" view showing around 4 or so images in each row. When an image is clicked on it takes you to that record. I know a report can be used to make rows but how do I get the images to display? They are stored in a folder and not actually embedded into the database. I have a VB code that displays the image on my forms but this doesn't work when it's a continuous form or report. It shows the same image until I click on that record then the image changes.
I have two tables, tblAdmin (which contains my attachment field, a logo) and tblRecords (which contains customer records.I created a form (frmMain) that displays customer records, and hooked frmMain to qrySelectCustomer, which is a query that... you guessed it!... selects a particular customer to view. I wanted the logo to appear at the top of this form, but it's in a separate table. I need to allow the database owner to go in and swap out one logo for another whenever he wants (if the business changes or whatever) and all my subsequent forms/reports have to pull this logo.
I can't use any kind of DLookUp for the image/attachment, because DLookUp only fetches text not images, so what I did was create a subform called frmLogo and hooked the subform to tblAdmin where the attachment resides. It works perfectly when I just open the frmLogo, the image displays as it should. But when I open frmMain, I get a parameter value prompt because it can't find the image! Even though the subform frmLogo that's on frmMain is hooked to the correct frmAdmin table!
I tried several things, but the only thing that solved the problem was to ALSO hook frmMain to tblAdmin, which I do NOT want to do, because then I have to create a THIRD form for the customer data and hook THAT to qrySelectCustomer!
I need to replace the embedded image on a large number of reports and forms. I'm looking for a way to loop through all of the controls in my forms and reports and if the control is an image, replace the embedded image with a new one. Can this be done using vba?
lets say i have a data field which contains hyperlink for a html file, can i display the content of the file from the hyperlink in the form when the form is loaded?
I know that Access can display images, I have seen it done. I am using Access 2013. I am trying to display a photo in a form field. In the underlying table I have tried using attachment and OLE Object data types and I couldn't get the picture to display with either.
I'm currently making a form to display employee info in a nice fashion..
Anyway I have the employee photo displayed in an image control.
I want to be able to apply some tricks to the borders to make it look better. To do that, I need to make the width property equal to the width of the actual image while the height is restrained
My end goal is to display an image for every row on a report and/or form.I reviewed the various options for that, and finally decided the best thing to do would be to put the images in a separate folder in my PC, and put the path for the image in a column in the main(primary) table.In my form or report, I put an Image Frame, and put the ImagePath column in the Control Source. All is well and good.
However, I realize the inherent problem with having the full path in every single row, since I could move the image folder and I'd be hosed.So, I created an Environment Variables table, and I have a column called ImageFolder. Then I changed the name of the column in the primary table to ImageName instead of ImagePath. My hope was to be able to concatenate ImagePath and ImageName as the Control Source on the form and report.
I couldn't figure out a way to do that, since they are in two different tables, with no direct relationship between the tables.For the report, I created a workaround by creating a query of all the fields, including a field which concatenated the path and the ImageName. But since I use the form/ sub form to update the records, that wouldn't work for the form. My next attempt was to try to add an ImagePath back again to the primary record, but to have it default to the value that's in the EnvironmentalVariables table.
I want to display the linked image in form view. 'ole object' has the property 'display type' as content or icon. but both settings shows only the icon and file name. 'attachment' field does show image in form view but attaching images (jpeg or png) will increase database size.