DataGrid with Picture - vb6

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")

Related

Inserting images in Access database as hyperlink

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

How to add a Add ins menu tab to Power Point 2007?

I am working with Power Point 2007 but there is no Add Ins menu tab and I can not find how to add it.
When PPT 2007 and onward runs code that creates "legacy" command bars or menu modifications, it automatically adds the Add-ins tab to the ribbon and puts the command bars/menu changes there. Here's some simple example code. You can run it as is, or save it as an add-in. Once the add-in is loaded, the Auto_Open code will run every time PPT starts up.
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim MyToolbar As String
' Give the toolbar a name
MyToolbar = "Kewl Tools"
On Error Resume Next
' so that it doesn't stop on the next line if the toolbar's already there
' Create the toolbar; PowerPoint will error if it already exists
Set oToolbar = CommandBars.Add(Name:=MyToolbar, _
Position:=msoBarFloating, Temporary:=True)
If Err.Number <> 0 Then
' The toolbar's already there, so we have nothing to do
Exit Sub
End If
On Error GoTo ErrorHandler
' Now add a button to the new toolbar
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
' And set some of the button's properties
With oButton
.DescriptionText = "This is my first button"
'Tooltip text when mouse if placed over button
.Caption = "Do Button1 Stuff"
'Text if Text in Icon is chosen
.OnAction = "Button1"
'Runs the Sub Button1() code when clicked
.Style = msoButtonIcon
' Button displays as icon, not text or both
.FaceId = 52
' chooses icon #52 from the available Office icons
End With
' Repeat the above for as many more buttons as you need to add
' Be sure to change the .OnAction property at least for each new button
' You can set the toolbar position and visibility here if you like
' By default, it'll be visible when created. Position will be ignored in PPT 2007 and later
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub ' so it doesn't go on to run the errorhandler code
ErrorHandler:
'Just in case there is an error
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub
Sub Button1()
' This code will run when you click Button 1 added above
' Add a similar subroutine for each additional button you create on the toolbar
' This is just some silly example code.
' You'd put your real working code here to do whatever
' it is that you want to do
MsgBox "Stop poking the pig!"
End Sub

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

Is there an Alternative to using the LoadPicture("bmp_or_icon_file_path") to loading Images in Excel 2007 VBA

I have an Excel 2007 Worksheet with many buttons and labels that act as menu options (i.e. user clicks the buttons, labels with images) and is presented with forms, or some thing else.
These images / icons for the buttons and labels are loaded in VBA by assigning the Picture property of the Control and calling LoadPicture() method with the full image file path as parameter, like So.
With SomeFormObject
.cmdOpenFile.Picture = LoadPicture("F:\projectname\images\fileopen.BMP")
End With
This method of loading images for buttons, other controls is causing 2 issues.
1) It creates a dependency on the image files and physical location for every user, so if a user does not have the drive mapped and files present, the VBA fails with runtime error of file or path not found.
2)
The app gets very slow if the images are on a shared drive (which is the case)
I want to eliminate both issues and somehow load icons, images into control internally, without any external dependencies on external image files.
What is the best way to achieve this in Excel 2007 VBA?
I could not file any Visual Basic 6.0 / Visual Studio style "Resource File Editor" / feature with which to accomplish this.
Please advice! thank you
-Shiva #
mycodetrip.com
I really hope that there is a easier way to do this, but this is the only one I found:
The Idea is:
You keep the Pictures embedded in a Sheet and every time you want to set the pictures for the Command you export them from your worksheet to a file and load them through LoadPicture. The only way to export an embedded Picture through VBA that I found is by making it a Chart first.
The following code is based on 'Export pictures from Excel' from johnske
Option Explicit
Sub setAllPictures()
setPicture "Picture 18", "CommandButtonOpen"
setPicture "Picture 3", "CommandButtonClose"
End Sub
Sub setPicture(pictureName As String, commandName As String)
Dim pictureSheet As Worksheet
Dim targetSheet As Worksheet
Dim embeddedPicture As Picture
Dim pictureChart As Chart
Dim MyPicture As String
Dim PicWidth As Long
Dim PicHeight As Long
Set pictureSheet = Sheets("NameOfYourPictureSheet") ' <- to Change '
Set targetSheet = Sheets("NameOfYourSheet") ' <- to Change '
Set embeddedPicture = pictureSheet.Shapes(pictureName).OLEFormat.Object
With embeddedPicture
MyPicture = .Name
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=pictureSheet.Name
Set pictureChart = ActiveChart
embeddedPicture.Border.LineStyle = 0
With pictureChart.Parent
.Width = PicWidth
.Height = PicHeight
End With
With pictureSheet
.Select
.Shapes(MyPicture).Copy
With pictureChart
.ChartArea.Select
.Paste
End With
.ChartObjects(1).Chart.Export Filename:="temp.jpg", FilterName:="jpg"
End With
pictureChart.Parent.Delete
Application.ScreenUpdating = True
targetSheet.Shapes(commandName).OLEFormat.Object.Object.Picture = LoadPicture("temp.jpg")
Set pictureChart = Nothing
Set embeddedPicture = Nothing
Set targetSheet = Nothing
Set pictureSheet = Nothing
End Sub
Sub listPictures()
' Helper Function to get the Names of the Picture-Shapes '
Dim pictureSheet As Worksheet
Dim sheetShape As Shape
Set pictureSheet = Sheets("NameOfYourSheet")
For Each sheetShape In pictureSheet.Shapes
If Left(sheetShape.Name, 7) = "Picture" Then Debug.Print sheetShape.Name
Next sheetShape
Set sheetShape = Nothing
Set pictureSheet = Nothing
End Sub
To Conclude:
Loading the Images from a Mapped Networked Drive seems less messy, and there shouldn't be that much of a speed difference.
2 alternatives i can think of: form.img.picture=pastepicture , and = oleobjects("ActiveXPictureName").object.picture.

Macro to wrap selected text with tags in Visual Studio

I realize that I may be being a bit lazy, but does anyone know of a Visual Studio macro, where I can select some text inside of the Visual Studio IDE, click a button, and have it wrap the selected text with tags? It would generate something like:
<strong>My Selected Text</strong>
I would even be up for creating a macro, just not sure where to exactly start!
The code to do so is rather simple:
Sub SurroundWithStrongTag()
DTE.ActiveDocument.Selection.Text = "<strong>" + DTE.ActiveDocument.Selection.Text + "</strong>"
End Sub
Now, if you don't know much about macros here's how to add it:
First you need open the macros IDE, click Tools->Macros->Macros IDE...
Next, we will add a module for your custom macros. Right click on "MyMacros" in the Project Explorer, click Add->Add Module..., type in an appropriate name then click "Add".
Now paste the function inside the module, making copies for any other tags you want
Save and close the macros IDE
To hook the macro up to a button:
Click Tools->Customize...
Click New..., type in an appropriate name, click OK. An empty toolbar should be visible (you may have to move the window to see it)
Click the Commands tab, and select "Macros" in categories
Find the macros created before and drag them over to the toolbar
Right click the buttons to change settings (such as displaying an icon instead of text)
I know this is an old topic, but maybe someone finds this useful.
I have the following set up:
Sub WrapInH1()
WrapInTag("h1")
End Sub
Sub WrapInP()
WrapInTag("p")
End Sub
Sub WrapInStrong()
WrapInTag("strong")
End Sub
Sub WrapInTag()
WrapInTag("")
End Sub
Sub WrapInTag(ByVal tagText As String)
EnableAutoComplete(False)
If tagText.Length = 0 Then
tagText = InputBox("Enter Tag")
End If
Dim text As String
text = DTE.ActiveDocument.Selection.Text
text = Regex.Replace(text, vbCrLf & "$", "") 'Remove the vbCrLf at the end of the line, for when you select the line by clicking in the margin, otherwise your closing tag ends up on it's own line at the end...
DTE.ActiveDocument.Selection.Text = "<" & tagText & ">" & text & "</" & tagText & ">" & vbCrLf
EnableAutoComplete(True)
End Sub
Private Sub EnableAutoComplete(ByVal enabled As Boolean)
Dim HTMLprops As Properties
Dim aProp As EnvDTE.Property
HTMLprops = DTE.Properties("Texteditor", "HTML Specific")
aProp = HTMLprops.Item("AutoInsertCloseTag")
aProp.Value = enabled
End Sub
Dim HTMLprops As Properties = DTE.Properties("Texteditor", "HTML Specific")
Dim aProp As EnvDTE.Property = HTMLprops.Item("AutoInsertCloseTag")
aProp.Value = False
Original answer
If you want an out of the box solution, Visual Studio 2015 comes with a new shortcut, Shift+Alt+W wraps the current selection with a div. This shortcut leaves the text "div" selected, making it seamlessly changeable to any desired tag. This coupled with the automatic end tag replacement makes for a quick solution.
Example
Shift+Alt+W > strong > Enter

Resources