Inserting images in Access database as hyperlink - image

I'm trying to insert an image path into an Access database. I have a hyperlink field named logo, and I'm using this code to browse for images:
Dim dialog As FileDialog
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
.AllowMultiSelect = False
.Title = "Select A File To Use As A Logo"
.Filters.Clear
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg;*.bmp;*.png"
.ButtonName = "Use This File"
If .Show = True Then
Me.im1 = .SelectedItems.Item(1)
End If
End With
im1 is an unbound textbox used to view the path. The problem is that it's displaying the file path as text, not as a hyperlink. I'd like to display the file name as a hyperlink in my form in im1. Is this possible?

Text is text. If you want something to show up as a hyperlink you need to tell your textbox that's what it's doing. It can't guess.
im1.IsHyperlink=True
However, The easier thing to do is probably to use a Label instead of a textbox. Set the .HyperlinkAddress property to your link address

Related

Insert a logo from a folder into excel

I am looking for a way to insert a picture from a folder into a specific cell in excel. The folder contains hundreds of pictures. I am not familiar with excel macros or VBA. The way the code should work is I type the picture name into a cell and the result should extract a picture with the same name from that folder and place it into another cell. The picture being inserted should also be resized. If someone could please give me some guidance as to how this could be done. Thanks. I am sorry for my poor English as it is my second language.
Assuming you are typing your image name as "myImage.jpg" into cell A1 of your worksheet. Make sure it is the full name with the extension. Place this into your worksheet code.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim imagePath, fullImagePath, newImageLoc As String
imagePath = "C:\YourFileLocationPath\" 'set this to where your images are located.
If Target.Address = "$A$1" Then 'Assumming the cell you are entering your image is in A1 or change to whatever cell you want entering in.
fullImagePath = imagePath & Target.Value
newImageLoc = Target.Offset(, 2).Address ' this moves the new image location to the cell you enter your image name two columns to the right.
'Adjusts image size, change as needed
With ActiveSheet.Pictures.Insert(fullImagePath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 75
.Height = 100
End With
.Left = ActiveSheet.Range(newImageLoc).Left
.Top = ActiveSheet.Range(newImageLoc).Top
.Placement = 1
.PrintObject = True
End With
End
End If
End Sub

Unbound imagecontrol ONLY show First image when imagelink is added in a 1:N relation

Background:
Entry is via a subform for adding/showing/linking images.
I do not want to store the image files within my DB, the image folder is separate. The DB will grow rather large in time.
I have created a click-control enabling a popup for user to browse and click on the imagePATH to be added in a Bound Textfield (called Bildadress, no not misspelled in My country, Grin ) in the subform.
See code below.
Then I add a new unbound Image-control and specify its Controlsource = the Textfield mentioned above.
For the firs image this works wonderful, but for the following the Image-control returns NULL (not show att all). The data in the Textfield updates as it should.
Will the 2nd stage only work in a 1:1 relationship OR can I (with your help) use VBA code to make this work?
OPTIMAL would be to get this to work and also a 2nd Bound Textfield just displaying the actual image file name. .
I hope someone out there have encountered this problem who also didnt want to use Attachment to store the files within the databae.
CODE:
Private Sub AddFilePath_Click()
Call Selectfile
End Sub
Public Function Selectfile() As String
Dim Fd As FileDialog
Set Fd = Application.FileDialog(msoFileDialogOpen)
With Fd
.AllowMultiSelect = False
.Title = "Välj önskad fil"
If .Show = True Then
Selectfile = .SelectedItems(1)
Me.Bildadress = Selectfile
Else
Exit Function
End If
End With
Set Fd = Nothing
End Function
If you use a bound textbox that holds the image-path then you can use
Me.Imagecontrol.Picture = Me.BoundTextControl.Value
to load the picture into an unbound image control. In your case that would be something like
If .Show = True Then
Me.Bildadress.value = .SelectedItems(1)
Me.Bild.Picture = Me.Bildadress.value
Else
It would be best to also load the respective picture in the OnCurrent Event.
Private Sub Form_Current()
Me.Bild.Picture = Me.Bildadress.value
End Sub
However, keep in mind that access is a one-file-database and you break that paradigm when using links to external files where the files would belong into the DB.

Excel VBA: end user select image on computer and submit on user form

I have a userform with a bunch of textboxes. End user inputs test data into form and after clicking "Submit" button, this info is saved to an excel sheet. I am wondering how to make it possible for user to input images from their computer into the form.
Requirements: End user be able to select an image from their computer and click submit on the form to have it inserted into an excel sheet.
Private Sub CommandButton3_Click()
Dim image As FileDialog
Set image = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedPicture As Variant
With image
If .Show = -1 Then
For Each vrtSelectedPicture In .SelectedItems
'Show path in textbox
TextBox71.Text = .SelectedItems(1)
Next vrtSelectedPicture
'The user pressed Cancel.
Else
End If
End With
'Set the object variable to Nothing
Set image = Nothing
End Sub
Sure, here is a sample code that may give you an idea about FileDialog.
Private Sub CommandButton1_Click()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select an image file"
.Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 1
If .Show = -1 Then
' file has been selected
' e.g. show path in textbox
Me.TextBox1.Text = .SelectedItems(1)
' e.g. display preview image in an image control
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
Me.Image1.Picture = LoadPicture(.SelectedItems(1))
Else
' user aborted the dialog
End If
End With
End Sub

Set displayed text of HyperLink on RadGrid load

I have a telerik RadGrid that gets populated with data from a SQL database when the grid loads. The first column lists a name, which needs to be a hyperlink to another part of the website. I have tried a couple different options, neither of which gets me the results I need.
The first way I tried was using a GridHyperLinkColumn. However that does not allow me to change the displayed text of the hyperlink programmatically when the grid gets populated with data.
<telerik:GridHyperLinkColumn DataNavigateUrlFields="joblink" DataNavigateUrlFormatString="/Job.aspx?id={0}" Text="JobName">
taskDR.Item("joblink") = dataReader("publicID")
taskDR.Item("joblink").Text = dataReader("name") 'This is what I would like to do
The other option was to use a GridBoundColumn and bind a Hyperlink to it.
<telerik:GridBoundColumn DataField="joblink" UniqueName="joblink">
Dim jobhyperlink As New HyperLink()
jobhyperlink.Text = dataReader("name")
jobhyperlink.NavigateUrl = "/Job.aspx?id=" & dataReader("publicID").ToString()
taskDR.Item("joblink") = jobhyperlink
However instead of displaying the hyperlink in the joblink column, all that displays is "System.Web.UI.WebControls.HyperLink"
I looked into the DataTextField and DataTextFormatString properties of GridHyperLinkColumn, but I couldn't find a way to alter those fields programmatically.
you can try a template column and just place a html tag and use Eval function to bind the things the way you want.
Check out this demo - http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx
I finally figured it out.
<telerik:GridHyperLinkColumn UniqueName="joblink" Text="jobname" DataNavigateUrlFields="joblink" DataNavigateUrlFormatString="/Employer/Job.aspx?action=edit&id={0}" DataTextField="jobname" DataTextFormatString="{0}">
Dim taskDT As New DataTable
taskDT.Columns.Add("jID")
taskDT.Columns.Add("jobname") 'You need one column for the DataTextField
taskDT.Columns.Add("joblink") 'and another for the DataNavigateUrlField
While dataReader.Read()
Dim taskDR = taskDT.NewRow()
taskDR.Item("jobname") = dataReader("name")
taskDR.Item("joblink") = dataReader("publicID")

DataGrid with Picture

I have a DataGrid in Visual Basic 6. This DataGrid displays a list of product just like what see below:
I want to change image in the Image control whenever the user selects a product from the DataGrid. I am doing this thru the code below:
Private Sub txtBarcode_Change()
On Error GoTo nosuchfile
picture.picture = App.Path & "Images\products\" & txtBarcode.Text & ".jpg"
nosuchfile:
picture.picture = App.Path & "Images\products\no_image.jpg"
End Sub
txtBarcode is a hidden textbox that contains the barcode/id that is currently selected in the DataGrid.
MY PROBLEM: The image doesn't seems to change.
to load a picture you need to call LoadPicture()
Picture1.Picture = LoadPicture("c:\temp\pic.bmp")

Resources