HDfatboy03
Board Regular
- Joined
- May 23, 2010
- Messages
- 62
Hello
I am need of help with VBA LoadPicture in a form based on a variable.
My combo box is the variable = cboitem
my image box is = Image1
my form is named = frmData
my pics are located = C:\Bob\Inventory_Tracker\
When the user ... lets say selects item # 13200 in the combo box ... I would like the
corresponding picture 13200.jpg to show up in the form (Image1). My form works but I can't
figure out the picture part. Here is what I have so far
----------------------------------------------
Private Sub cboItem_Change()
Dim r As Long
r = Me.cboItem.ListIndex + 2
Me.txtLoc.Value = Worksheets("DB").Cells(r, 11).Value
Me.txtDesc.Value = Worksheets("Db").Cells(r, 3).Value
Me.txtQty.Value = Worksheets("Db").Cells(r, 4).Value
Me.txtCost.Value = Worksheets("Db").Cells(r, 10).Value
End Sub
Private Sub cmdADD6_Click()
Dim iRow As Long
w = CLng(Me.txtLoc.Text)
Dim ws As Worksheet
Dim ws2 As Worksheet
Set ws2 = Worksheets("Db")
Set ws = Worksheets("Cart")
Set ws2 = Worksheets("Db")
'calculation for inventory sold
Dim Z As Integer
x = CLng(Me.txtQty.Text)
y = CLng(Me.txtBuy.Text)
Z = x - y
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'copy the data to Cart
ws.Cells(iRow, 1).Value = Me.cboItem.Value
ws.Cells(iRow, 2).Value = Me.txtDesc.Value
ws.Cells(iRow, 3).Value = Me.txtCost.Value
ws.Cells(iRow, 4).Value = Me.txtBuy.Value
ws.Cells(iRow, 5).Value = Me.txtPrice.Value
'copy adjusted inventory level
ws2.Cells(w, "D").Value = Z
'clear the data
Me.cboItem.Value = ""
Me.txtDesc.Value = ""
Me.txtCost.Value = ""
Me.txtBuy.Value = ""
Me.txtPrice.Value = ""
End Sub
Private Sub cmdCLOSE_Click()
Unload Me
End Sub
Private Sub Image1_Click()
End Sub
Private Sub Label9_Click()
End Sub
Private Sub txtDate_Change()
End Sub
Private Sub UserForm_Initialize()
'adds date automatically
Me.txtDate.Value = Format(Date, "Medium Date")
End Sub
------------------------------------------------
In my research I have found this code ... but I am unable to fit into my existing code ...
please help
------------------------------------------------
Private Sub UserForm_Initialize()
PicFile = Dir("C:\Bob\Inventory_Tracker\*.jpg")
Do While PicFile <> ""
PicFile = Dir
cboitem.AddItem PicFile, cboitem.ListCount
Loop
End Sub
Private Sub cboitem_Change()
On Error GoTo NoPic
Image1.Picture = LoadPicture("C:\Bob\Inventory_Tracker\" & cboitem.Value)
Exit Sub
NoPic:
Image1.Picture = LoadPicture()
End Sub
------------------------------------------------
Any help will be greatly appreciated ... thanks in advance ... Bob
I am need of help with VBA LoadPicture in a form based on a variable.
My combo box is the variable = cboitem
my image box is = Image1
my form is named = frmData
my pics are located = C:\Bob\Inventory_Tracker\
When the user ... lets say selects item # 13200 in the combo box ... I would like the
corresponding picture 13200.jpg to show up in the form (Image1). My form works but I can't
figure out the picture part. Here is what I have so far
----------------------------------------------
Private Sub cboItem_Change()
Dim r As Long
r = Me.cboItem.ListIndex + 2
Me.txtLoc.Value = Worksheets("DB").Cells(r, 11).Value
Me.txtDesc.Value = Worksheets("Db").Cells(r, 3).Value
Me.txtQty.Value = Worksheets("Db").Cells(r, 4).Value
Me.txtCost.Value = Worksheets("Db").Cells(r, 10).Value
End Sub
Private Sub cmdADD6_Click()
Dim iRow As Long
w = CLng(Me.txtLoc.Text)
Dim ws As Worksheet
Dim ws2 As Worksheet
Set ws2 = Worksheets("Db")
Set ws = Worksheets("Cart")
Set ws2 = Worksheets("Db")
'calculation for inventory sold
Dim Z As Integer
x = CLng(Me.txtQty.Text)
y = CLng(Me.txtBuy.Text)
Z = x - y
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'copy the data to Cart
ws.Cells(iRow, 1).Value = Me.cboItem.Value
ws.Cells(iRow, 2).Value = Me.txtDesc.Value
ws.Cells(iRow, 3).Value = Me.txtCost.Value
ws.Cells(iRow, 4).Value = Me.txtBuy.Value
ws.Cells(iRow, 5).Value = Me.txtPrice.Value
'copy adjusted inventory level
ws2.Cells(w, "D").Value = Z
'clear the data
Me.cboItem.Value = ""
Me.txtDesc.Value = ""
Me.txtCost.Value = ""
Me.txtBuy.Value = ""
Me.txtPrice.Value = ""
End Sub
Private Sub cmdCLOSE_Click()
Unload Me
End Sub
Private Sub Image1_Click()
End Sub
Private Sub Label9_Click()
End Sub
Private Sub txtDate_Change()
End Sub
Private Sub UserForm_Initialize()
'adds date automatically
Me.txtDate.Value = Format(Date, "Medium Date")
End Sub
------------------------------------------------
In my research I have found this code ... but I am unable to fit into my existing code ...
please help
------------------------------------------------
Private Sub UserForm_Initialize()
PicFile = Dir("C:\Bob\Inventory_Tracker\*.jpg")
Do While PicFile <> ""
PicFile = Dir
cboitem.AddItem PicFile, cboitem.ListCount
Loop
End Sub
Private Sub cboitem_Change()
On Error GoTo NoPic
Image1.Picture = LoadPicture("C:\Bob\Inventory_Tracker\" & cboitem.Value)
Exit Sub
NoPic:
Image1.Picture = LoadPicture()
End Sub
------------------------------------------------
Any help will be greatly appreciated ... thanks in advance ... Bob