Private Sub btnSearch_Click()Call ClearClipboard
Me.btnSearch.Visible = True
Me.CBSearchCatagory.Visible = True
Me.CBSearchResult.Visible = True
Me.cmdUpdate.Visible = True
Me.cmdAdd.Visible = True
Dim FoundCell As Range
Dim MoveToTwoRowsDown As Range
If Me.CBSearchResult.Value = "" Then
Me.tbCVCNo.Enabled = True
With Me.CBSearchResult
End With
If Me.CBSearchCatagory.Value = "Search by CVC Number" Or _
Me.CBSearchCatagory.Value = "Search by Nasico UID Number" Or _
Me.CBSearchCatagory.Value = "Search by Tag Number" Or _
Me.CBSearchCatagory.Value = "Search by Customer" Or _
Me.CBSearchCatagory.Value = "Search by Valve Manufacturer" Or _
Me.CBSearchCatagory.Value = "Search by Job Number" And _
Me.CBSearchResult = "" Then Exit Sub
Me.CBSearchResult.Visible = True
End If
If Me.CBSearchResult.ListIndex = 0 Then
Beep
Exit Sub
End If
If Me.CBSearchCatagory.Value = "Search by CVC Number" And Me.tbCVCNo.Value = Me.CBSearchResult Then
With CBSearchResult
Application.ScreenUpdating = False
Set FoundCell = Cells.Find(what:=Me.CBSearchResult.Value, _
After:=Cells(1), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
If Not FoundCell Is Nothing Then
' Set MoveToTwoRowsDown = FoundCell.Offset(2, 0)
Beep
Me.tbUIDNO.Value = FoundCell.Offset(0, 1).Value
Me.tbTAGNO.Value = FoundCell.Offset(0, 2).Value
'.....
'......
'.........
Me.TextBox333.Value = FoundCell.Offset(0, 455)
Me.ComboBox21.Value = FoundCell.Offset(0, 456)
Me.VSDJOBNO.Value = FoundCell.Offset(0, 457)
If FoundCell.Offset(0, 458).Value = "Dammam" Then Me.CBLOCATION.Value = "D"
If FoundCell.Offset(0, 458).Value = "Jubail" Then Me.CBLOCATION.Value = "J"
Me.timestamp.Caption = FoundCell.Offset(0, 459) = Format(timestamp.Caption, "mmmm dd yyyy hh:mm")
Me.TextBox295.Value = FoundCell.Offset(0, 460)
Me.TextBox302.Value = FoundCell.Offset(0, 461)
If FoundCell.Offset(0, 462).Value = "AFO" Then Me.OptionButton70.Value = True
If FoundCell.Offset(0, 462).Value = "AFC" Then Me.OptionButton71.Value = True
If FoundCell.Offset(0, 463).Value = "AFO" Then Me.OptionButton72.Value = True
If FoundCell.Offset(0, 463).Value = "AFC" Then Me.OptionButton73.Value = True
Call ClearClipboard
'Picture1-Comment Copy to userform
'Picture1-Label Copy to userform
Dim wsImageCopies1, wsinit1 As Worksheet
Dim oImage As image
Dim oShape, CopyImage1, PasteImage1 As shape
Dim oChart As Chart
Dim sTempFilename1, strInitDir1 As String
Dim s As Double
Dim l As Double
Dim t As Double
Dim h As Double
'Assign a filename for the temporary image
sTempFilename1 = Environ("temp") & "\temp_" & Format(Now, "yy-mm-dd_hh-mm-ss") & ".jpg"
'Dim s, l, t, h As Long
s = 260
t = 100
l = 24
h = 24
If FoundCell.Offset(0, 484).Text > 0 Then
Set wsinit1 = ActiveSheet
strInitDir1 = CurDir 'Optional: Save directory so can return to it.
MultiPage1.Pages.Add
Dim lblCaption1 As MSForms.Label
On Error GoTo Err_Clr
Set lblCaption1 = MultiPage1.Pages(7).Controls.Add("Forms.label.1", "myLabelCaption")
With lblCaption1
.Font.Name = "Arial Black"
.Font.Size = 14
.TextAlign = fmTextAlignCenter
.Width = s
.Height = h
.Left = l
.Top = t + s
.ForeColor = vbWhite
.BackColor = &H800000
.WordWrap = False
.AutoSize = False
.Enabled = True
.Caption = FoundCell.Offset(0, 484).Value
Me.Repaint
End With
'Add and set the properties for an image control on the second page of the multipage control
Set oImage = Me.MultiPage1.Pages(7).Controls.Add("Forms.Image.1")
With oImage
.Name = "image1"
.Left = l
.Top = t
.Width = s
.Height = s
'Sheets("ImageCopies1").Activate
' ThisWorkBook.Worksheets("ImageCopies1").ChartObjects(1).Chart.CopyPicture xlScreen, xlPicture, xlScreen
' Dim sel As Range
'Set sel = .Offset(FoundCell(2, 0))
'Range("C5").Offset(1, 2)
'Range(MoveToTwoRowsDown).Select
'Set MoveToTwoRowsDown = Selection.Offset(0, 464).Resize(Selection.Rows.Count + 2, _
Selection.Columns.Count).Select
'Selection(MoveToTwoRowsDown) = FoundCell.Offset(0, "QW").Resize(Rows.Count + 2, Columns.Count + 0).Select
'Set CopyImage1 = Worksheets("Data").Cells(FoundCell.Offset(2, 464).Resize(Rows.Count + 2, Columns.Count), 464)
' Set CopyImage1 = Worksheets("Data").Cells(FoundCell.Offset(0, "QW").Resize(FoundCell.Offset(FoundCell.Rows.Count + 2, FoundCell.Columns.Count).Select), "QW")
'ActiveCell.Offset(0, 464).Select
'Sheets("Data").Activate
'Below code works but copies 2 cells above the foumdcell row
'because I am having 2 rows of table headings
'Any advice,,,,xxxxxxxxxxxxxxx
'xxxxxxxxxxxxxxxxxxxx
'xxxxxxxxxxxxxxx
Set CopyImage1 = Worksheets("Data").Cells(FoundCell.Offset, "QW")
CopyImage1.CopyPicture xlScreen, xlPicture
Set MultiPage1.Pages(7).image1.Picture = PastePicture
.PictureSizeMode = fmPictureSizeModeStretch
End With
Else: Exit Sub
Call ClearClipboard
End If
End If
'End If
Err_Clr:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End With
End If
End Sub
'------
Public Function ClearClipboard()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
End Function