".Text" property not defined? - vb6

I have tried activating multiple resources, but whatever I do, the .Text method is not defined / recognized, the .Text is in the following line of code:
Private Sub Form_Load()
StartDate = Date
meBakBlauw.Text = "-"
meBakGeel.Text = "-"
The prompt that comes up after running it says: 'Method or Datamember is not found'.
Is there somebody that knows how to fix this?
It's written by our old programmer where he build in a restricting on resources that expanded. It's written in Visual Basic 6.
The full program:
VERSION 5.00
Begin VB.Form frmKoppelBak
BackColor = &H80000005&
Caption = "Bakken Koppelen"
ClientHeight = 9285
ClientLeft = 60
ClientTop = 750
ClientWidth = 13590
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 9285
ScaleWidth = 13590
Begin VB.PictureBox meBakGeel
BackColor = &H0000FFFF&
Enabled = 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 72
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 1440
Left = 7080
ScaleHeight = 1380
ScaleWidth = 5940
TabIndex = 6
TabStop = 0 'False
Top = 2280
Width = 6000
End
Begin VB.PictureBox meBakBlauw
BackColor = &H00FF0000&
Enabled = 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 72
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 1440
Left = 7080
ScaleHeight = 1380
ScaleWidth = 5940
TabIndex = 5
TabStop = 0 'False
Top = 600
Width = 6000
End
Begin VB.PictureBox meBlauw
Appearance = 0 'Flat
Enabled = 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 72
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 1455
Index = 0
Left = 480
ScaleHeight = 1425
ScaleWidth = 6345
TabIndex = 4
TabStop = 0 'False
Top = 600
Width = 6375
End
Begin VB.PictureBox PVMaskEdit4
Appearance = 0 'Flat
Enabled = 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 48
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 1455
Left = 495
ScaleHeight = 1425
ScaleWidth = 6345
TabIndex = 3
TabStop = 0 'False
Top = 7200
Width = 6375
End
Begin VB.PictureBox PVMaskEdit3
Appearance = 0 'Flat
BackColor = &H80000014&
Enabled = 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 48
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 1455
Left = 480
ScaleHeight = 1425
ScaleWidth = 6345
TabIndex = 2
TabStop = 0 'False
Top = 5520
Width = 6375
End
Begin VB.PictureBox meScanOrder
CausesValidation= 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 48
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 1440
Left = 7080
ScaleHeight = 1380
ScaleWidth = 5940
TabIndex = 0
Top = 5520
Width = 6000
End
Begin VB.PictureBox meScanBak
BackColor = &H0000FFFF&
CausesValidation= 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 48
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 1440
Left = 7080
ScaleHeight = 1380
ScaleWidth = 5940
TabIndex = 1
Top = 7200
Width = 6000
End
Begin VB.PictureBox meBlauw
Appearance = 0 'Flat
Enabled = 0 'False
BeginProperty Font
Name = "Arial Black"
Size = 72
Charset = 0
Weight = 900
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 1455
Index = 1
Left = 480
ScaleHeight = 1425
ScaleWidth = 6345
TabIndex = 7
TabStop = 0 'False
Top = 2280
Width = 6375
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 10000
Left = 255
Top = 75
End
Begin VB.Frame Frame1
BackColor = &H80000005&
Caption = "Koppel Order aan Bak"
Height = 4095
Left = 120
TabIndex = 8
Top = 4920
Width = 13320
End
Begin VB.Menu File
Caption = "&File"
Begin VB.Menu mnuExit
Caption = "&Exit"
End
End
End
Attribute VB_Name = "frmKoppelBak"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10
Const glBlauweBak As Long = 1
Const glGeleBak As Long = 2
Const glNeeGELEBak As Long = 3
Const glOrderOnbekend As Long = 4
Const glNietVoorLegborden As Long = 5
Const glOngeldigBakNummer As Long = 6
Dim INIfile As String
Dim StartDate As Date
Dim ConnectOK As Boolean
Dim ChildHDL As Variant
Dim GeleBak As Boolean
Dim pp5000 As ADODB.Connection
Dim KoppelBak As ADODB.Command
Dim BakkenPerKleur As ADODB.Command
Dim PakOrder As ADODB.Command
Dim ConnStrPP5000 As String
Dim winTop As Integer
Dim winLeft As Integer
Dim winHeight As Integer
Dim winWidth As Integer
Dim wavBlauweBak As String
Dim wavGeleBak As String
Dim wavNeeGELEBak As String
Dim wavNietVoorLegborden As String
Dim wavOrderOnbekend As String
Dim wavOngeldigBakNummer As String
Private Declare Function GetPrivateProfileString _
Lib "kernel32" _
Alias "GetPrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString _
Lib "kernel32" _
Alias "WritePrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
Private Declare Function sndPlaySound _
Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Private Sub Form_Load()
StartDate = Date
meBakBlauw.Text = "-"
meBakGeel.Text = "-"
INIfile = App.Path & "\KoppelBak.ini"
GetSettings
ConnectOK = False
connectDB
If Not ConnectOK Then
MsgBox "ERROR: Geen verbinding met de database", vbCritical, "Koppel Bak"
Unload Me
End
End If
Me.Top = winTop
Me.Left = winLeft
TelBakken
Timer1.Enabled = True
End Sub
Private Sub Form_Resize()
If (frmKoppelBak.WindowState <> vbMinimized) Then
If (frmKoppelBak.Width <> 13710) Then
frmKoppelBak.Width = 13710
End If
If (frmKoppelBak.Height <> 10095) Then
frmKoppelBak.Height = 10095
End If
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim INIresult As Long
disconnectDB
If (frmKoppelBak.WindowState <> vbMinimized) Then
INIresult = WritePrivateProfileString("Settings", "winTop", CStr(Me.Top), INIfile)
INIresult = WritePrivateProfileString("Settings", "winLeft", CStr(Me.Left), INIfile)
End If
End Sub
Sub Geluidje(GeluidNR As Long)
Dim SoundName As String
Dim wFlags, playRes As Long
wFlags = SND_ASYNC Or SND_NODEFAULT
SoundName = ""
Select Case GeluidNR
Case glBlauweBak
SoundName = wavBlauweBak
Case glGeleBak
SoundName = wavGeleBak
Case glNeeGELEBak
SoundName = wavNeeGELEBak
Case glOrderOnbekend
SoundName = wavOrderOnbekend
Case glNietVoorLegborden
SoundName = wavNietVoorLegborden
Case glOngeldigBakNummer
SoundName = wavOngeldigBakNummer
Case Else
SoundName = "Windows XP Hardwarefout.wav"
End Select
If (SoundName <> "") Then
playRes = sndPlaySound(SoundName, wFlags)
End If
End Sub
Private Sub mnuExit_Click()
Unload frmKoppelBak
End Sub
Private Sub Timer1_Timer()
Dim INIresult As Long
Timer1.Enabled = False
If (Timer > 18000) Then '05:00
If Not ConnectOK Then
connectDB
End If
TelBakken
Else
If ConnectOK Then
disconnectDB
End If
If (StartDate < Date) Then 'nieuwe instance starten en zelf stoppen i.v.m memory leaks
If (frmKoppelBak.WindowState <> vbMinimized) Then
INIresult = WritePrivateProfileString("Settings", "winTop", CStr(Me.Top), INIfile)
INIresult = WritePrivateProfileString("Settings", "winLeft", CStr(Me.Left), INIfile)
End If
ChildHDL = Shell(App.Path & "\" & App.EXEName, vbNormalNoFocus)
If ChildHDL <> 0 Then
Unload frmKoppelBak
End
End If
End If
End If
Timer1.Enabled = True
End Sub
Private Sub TelBakken()
meBakBlauw.Text = "-"
meBakGeel.Text = "-"
BakkenPerKleur.Execute , , adExecuteNoRecords
meBakBlauw.Text = CStr(BakkenPerKleur.Parameters("#o_BlauweBakken").Value)
meBakGeel.Text = CStr(BakkenPerKleur.Parameters("#o_GeleBakken").Value)
End Sub
Private Sub meScanOrder_GotFocusEvent()
meScanOrder.Text = ""
End Sub
Private Sub meScanOrder_KeyPress(KeyAscii As Integer)
Dim FoutCode As Long
If KeyAscii = 13 Then
' Zoek de order en bepaal de bakkleur
meScanBak.Text = ""
Timer1.Enabled = False
PakOrder.Parameters("#i_AUFTRAG").Value = meScanOrder.Text
PakOrder.Execute , , adExecuteNoRecords
Timer1.Enabled = True
FoutCode = PakOrder.Parameters("#o_FoutCode").Value
GeleBak = PakOrder.Parameters("#o_GeleBak").Value
'MsgBox CStr(FoutCode) & "; " & CStr(GeleBak)
If (FoutCode = 0) Then
If GeleBak Then
meScanBak.ForeColor = &H0&
meScanBak.BackColor = &HFFFF&
Call Geluidje(glGeleBak)
Else
meScanBak.ForeColor = &HFFFFFF
meScanBak.BackColor = &HFF0000
Call Geluidje(glBlauweBak)
End If
' Nu naar het baknummer
meScanBak.SetFocus
Else
If (FoutCode = 1) Then
Call Geluidje(glOrderOnbekend)
Else
Call Geluidje(glNietVoorLegborden)
End If
meScanOrder.Text = ""
meScanOrder.SetFocus
End If
End If
End Sub
Private Sub meScanBak_GotFocusEvent()
meScanBak.Text = ""
End Sub
Private Sub meScanBak_KeyPress(KeyAscii As Integer)
Dim sBakNR As String
Dim iBakNR As Long
If KeyAscii = 13 Then
sBakNR = meScanBak.Text
If (Len(sBakNR) = 4) And IsNumeric(sBakNR) Then
iBakNR = CLng(sBakNR)
If GeleBak And (iBakNR > 1049) Then
Geluidje (glNeeGELEBak)
meScanBak.Text = ""
meScanBak.SetFocus
ElseIf (iBakNR < 1000) Or (iBakNR > 1450) Then
Geluidje (glOngeldigBakNummer)
meScanBak.Text = ""
meScanBak.SetFocus
Else
'pp5000.BeginTrans
Timer1.Enabled = False
With KoppelBak
.Parameters("rVal").Value = 0
.Parameters("#terminal_id").Value = ""
.Parameters("#i_Ordernr").Value = meScanOrder.Text
.Parameters("#i_HuidigeBak").Value = ""
.Parameters("#i_NieuweBak").Value = sBakNR
.Parameters("#i_HuidigeZone").Value = ""
.Execute , , adExecuteNoRecords
End With
'pp5000.CommitTrans
TelBakken
Timer1.Enabled = True
meScanBak.Text = ""
meScanOrder.Text = ""
meScanOrder.SetFocus
End If
End If
End If
End Sub
Sub connectDB()
Dim iloop As Integer
On Error GoTo CheckConnectError
If (pp5000 Is Nothing) Then
Set pp5000 = New ADODB.Connection
ElseIf (pp5000.State <> adStateClosed) Then
pp5000.Close
End If
pp5000.ConnectionString = ConnStrPP5000
'pp5000.Properties("Multiple Connections") = True
'pp5000.ConnectionString = "Driver={SQL Native Client};Server=LT-KTS\SQLEXPRESS;Database=PP5000-v36;Uid=eks;Pwd=kardex."
pp5000.Open
Set KoppelBak = New ADODB.Command
With KoppelBak
.ActiveConnection = pp5000
.CommandText = "EKS_Koppel_Bak"
.CommandType = adCmdStoredProc
.NamedParameters = False
.Parameters.Append .CreateParameter("rVal", adInteger, adParamReturnValue, 8, 0)
.Parameters.Append .CreateParameter("#terminal_id", adVarChar, adParamInput, 24, "")
.Parameters.Append .CreateParameter("#i_Ordernr", adVarChar, adParamInput, 20, "")
.Parameters.Append .CreateParameter("#i_HuidigeBak", adVarChar, adParamInput, 20, "")
.Parameters.Append .CreateParameter("#i_NieuweBak", adVarChar, adParamInput, 20, "")
.Parameters.Append .CreateParameter("#i_HuidigeZone", adVarChar, adParamInput, 20, "")
End With
Set BakkenPerKleur = New ADODB.Command
With BakkenPerKleur
.ActiveConnection = pp5000
.CommandText = "EKS_BakkenPerKleur"
.CommandType = adCmdStoredProc
.NamedParameters = True
.Parameters.Append .CreateParameter("#o_BlauweBakken", adInteger, adParamOutput)
.Parameters.Append .CreateParameter("#o_GeleBakken", adInteger, adParamOutput)
End With
Set PakOrder = New ADODB.Command
With PakOrder
.ActiveConnection = pp5000
.CommandText = "EKS_PakOrder"
.CommandType = adCmdStoredProc
.NamedParameters = True
.Parameters.Append .CreateParameter("#i_AUFTRAG", adVarChar, adParamInput, 20, "")
.Parameters.Append .CreateParameter("#o_FoutCode", adInteger, adParamOutput)
.Parameters.Append .CreateParameter("#o_GeleBak", adBoolean, adParamOutput)
End With
ConnectOK = True
Exit Sub
CheckConnectError:
If Not (pp5000 Is Nothing) Then
If (pp5000.Errors.Count > 0) Then
For iloop = 1 To pp5000.Errors.Count
MsgBox "ERROR:" & vbCrLf & _
"Description = " & pp5000.Errors.Item(iloop - 1).Description & vbCrLf & _
"NativeError = " & CStr(pp5000.Errors.Item(iloop - 1).NativeError) & vbCrLf & _
"Number = " & CStr(pp5000.Errors.Item(iloop - 1).Number) & vbCrLf & _
"Source = " & pp5000.Errors.Item(iloop - 1).Source & vbCrLf & _
"SQLState = " & pp5000.Errors.Item(iloop - 1).SQLState, vbCritical, "PP database"
Next iloop
End If
End If
End Sub
Sub disconnectDB()
If Not (pp5000 Is Nothing) Then
If Not (KoppelBak Is Nothing) Then
Set KoppelBak.ActiveConnection = Nothing
Set KoppelBak = Nothing
End If
If Not (BakkenPerKleur Is Nothing) Then
Set BakkenPerKleur.ActiveConnection = Nothing
Set BakkenPerKleur = Nothing
End If
If (pp5000.State = adStateOpen) Then
pp5000.Close
End If
Set pp5000 = Nothing
End If
ConnectOK = False
End Sub
Public Sub GetSettings()
Dim INIresult As Long
Dim INIvalue As String
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Settings", "winTop", "0", INIvalue, 255, INIfile)
If (INIresult > 0) Then
winTop = CInt(Left(INIvalue, INIresult))
End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Settings", "winLeft", "0", INIvalue, 255, INIfile)
If (INIresult > 0) Then
winLeft = CInt(Left(INIvalue, INIresult))
End If
' INIvalue = String(255, vbNullChar)
' INIresult = GetPrivateProfileString("Settings", "winHeight", "3600", INIvalue, 255, INIfile)
' If (INIresult > 0) Then
' winHeight = CInt(Left(INIvalue, INIresult))
' End If
'
' INIvalue = String(255, vbNullChar)
' INIresult = GetPrivateProfileString("Settings", "winWidth", "4680", INIvalue, 255, INIfile)
' If (INIresult > 0) Then
' winWidth = CInt(Left(INIvalue, INIresult))
' End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Connection", "ConnStrPP5000", "Driver={SQL Native Client};Server=schuurkx\sqlexpress;Database=PP5000-v36;Uid=eks;Pwd=kardex.", INIvalue, 255, INIfile)
If (INIresult > 0) Then
ConnStrPP5000 = Left(INIvalue, INIresult)
End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Geluiden", "BlauweBak", "", INIvalue, 255, INIfile)
If (INIresult > 0) Then
wavBlauweBak = Left(INIvalue, INIresult)
End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Geluiden", "GeleBak", "", INIvalue, 255, INIfile)
If (INIresult > 0) Then
wavGeleBak = Left(INIvalue, INIresult)
End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Geluiden", "NeeGELEBak", "", INIvalue, 255, INIfile)
If (INIresult > 0) Then
wavNeeGELEBak = Left(INIvalue, INIresult)
End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Geluiden", "OrderOnbekend", "", INIvalue, 255, INIfile)
If (INIresult > 0) Then
wavOrderOnbekend = Left(INIvalue, INIresult)
End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Geluiden", "NietVoorLegborden", "", INIvalue, 255, INIfile)
If (INIresult > 0) Then
wavNietVoorLegborden = Left(INIvalue, INIresult)
End If
INIvalue = String(255, vbNullChar)
INIresult = GetPrivateProfileString("Geluiden", "OngeldigBakNummer", "", INIvalue, 255, INIfile)
If (INIresult > 0) Then
wavOngeldigBakNummer = Left(INIvalue, INIresult)
End If
End Sub
I hope this gives some more clarification to what it is and does?

Every single control on that form is a PictureBox. That normally happens if upon loading a project, VB can't resolve the (COM) references in the project file (*.vbp). In such cases, VB throws an error message upon startup and replaces any control with a PictureBox as a placeholder.
It should have also created a file called frmKoppelBak.log in the folder where the form resides, providing more information.
And I hope you haven't saved the changes of that form (or have backups), otherwise you're stuck with th PictureBoxes. This might have happened, because you started VB6 under a normal user account on an OS > XP. Try launching the VB IDE 'As Administrator'

Related

ABCPDF Reading PDF as background image, next page doesnt render

We have 4 Html pages that we are joining together into 1 file.
For the first page, we are reading a blank PDF file (letter head) to add as the background and then add the further 3 pages.
However, all seemed ok in version 8, but now the second page will not show.
thedoc reads the blank pdf and then the html page which overlays the text no issue here.
thedoc1 is the second page which will not load
thedoc1a and thedoc2 load ok.
If I remove the adding of the letter head from thedoc, then all 4 pages load ok, but as soon as I try and use the letter head, the second page doesnt load.
Ive added my script below. What I am doing wrong please
Sub page_load()
Dim rs
Dim strSQLQuery As String
Dim theDoc As Doc = New Doc()
Dim theDoc1 As Doc = New Doc()
Dim theDoc1a As Doc = New Doc()
Dim theDoc2 As Doc = New Doc()
Dim theDoccontents As Doc = New Doc()
theDoc.MediaBox.String = "A4"
theDoc1.MediaBox.String = "A4"
theDoc1a.MediaBox.String = "A4"
theDoc2.MediaBox.String = "A4
theDoc.HtmlOptions.PageCacheEnabled = False
theDoc.HtmlOptions.PageCacheClear()
theDoc.HtmlOptions.ImageQuality = 33
theDoc1.HtmlOptions.ImageQuality = 33
theDoc1a.HtmlOptions.ImageQuality = 33
theDoc2.HtmlOptions.ImageQuality = 33
theDoc.HtmlOptions.AddLinks = True
theDoc1.HtmlOptions.AddLinks = True
theDoc1a.HtmlOptions.AddLinks = True
theDoc2.HtmlOptions.AddLinks = True
theDoc.HtmlOptions.Timeout = 10000000
theDoc1.HtmlOptions.Timeout = 10000000
theDoc1a.HtmlOptions.Timeout = 10000000
theDoc2.HtmlOptions.Timeout = 10000000
Dim rbrandchosen As String
Dim quotenumber As String
Dim rnum As String
Dim cover as string
dim pagex as integer
quotenumber=request("quotenumber")
rbrandchosen=request("rbrandchosen")
response.write(quotenumber)
Dim theURL As String
Dim theID As Integer
Dim strsql as string
Dim theSection as string
Dim theCountDoc1a As Integer
Randomize()
rnum = (CInt(Math.Floor(90 * Rnd())) + 10).ToString
' add covering letter
cover = "c:\\inetpub\\wwwroot\\icopalukintranet\\pnf\\letterhead.pdf"
theDoc.Read(cover)
'theID = theDoc.AddObject("<< >>")
theDoc.HtmlOptions.UseScript = True
theDoc.HtmlOptions.Engine = EngineType.Chrome86
' Render after 2 seconds
theDoc.Rect.SetRect(20, 110, 600, 620)
theDoc.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 3000); })();"
theURL = "http://localhost/icopalukintranet/pnf/rooflights/rooflightquotepdfletter.asp?quotenumber="+ quotenumber + "&stridrnd="+rnum
'theDoc.AddImageUrl(theURL)
theID = theDoc.AddImageUrl(theURL)
While True
If Not theDoc.Chainable(theID) Then
Exit While
End If
theDoc.Page = theDoc.AddPage()
theID = theDoc.AddImageToChain(theID)
End While
' add quote
theDoc1.HtmlOptions.Engine = EngineType.Chrome86
theDoc1.HtmlOptions.UseScript = True
theDoc1.Rect.SetRect(0, 0, 600, 820)
' Render after 2 seconds
theDoc1.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 2000); })();"
theURL = "http://localhost/icopalukintranet/pnf/rooflights/rooflightquotepdfquote.asp?quotenumber="+ quotenumber + "&stridrnd="+rnum
theDoc1.Page = theDoc1.AddPage()
theID = theDoc1.AddImageUrl(theURL)
While True
If Not theDoc1.Chainable(theID) Then
Exit While
End If
theSection = "Quote"
theDoc1.Page = theDoc1.AddPage()
theID = theDoc1.AddImageToChain(theID)
theDoc1.AddBookmark(theSection, True)
End While
' add notes
theDoc1a.HtmlOptions.Engine = EngineType.Chrome86
theDoc1a.HtmlOptions.UseScript = True
theDoc1a.Rect.SetRect(0, 0, 600, 820)
' Render after 3 seconds
theDoc1a.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 1000); })();"
theURL = "http://localhost/icopalukintranet/pnf/rooflights/rooflightquotepdfnotes.asp?quotenumber="+ quotenumber + "&stridrnd="+rnum
theDoc1a.Page = theDoc1a.AddPage()
theID = theDoc1a.AddImageUrl(theURL)
While True
If Not theDoc1a.Chainable(theID) Then
Exit While
End If
theDoc1a.Page = theDoc1a.AddPage()
theID = theDoc1a.AddImageToChain(theID)
End While
' add terms details
theDoc2.HtmlOptions.Engine = EngineType.Chrome86
theDoc2.HtmlOptions.UseScript = True
theDoc2.Rect.SetRect(20, 80, 560, 710)
theDoc2.Transform.Magnify(0.93 ,0.93, 0, 690)
' Render after 1 seconds
theDoc2.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 2000); })();"
theURL = "http://localhost/icopalukintranet/pnf/rooflights/rooflightquotepdfterms.asp?quotenumber="+ quotenumber + "&stridrnd="+rnum
theDoc2.Page = theDoc2.AddPage()
theID = theDoc2.AddImageUrl(theURL)
While True
If Not theDoc2.Chainable(theID) Then
Exit While
End If
theSection = "Terms"
theDoc2.Page = theDoc2.AddPage()
theID = theDoc2.AddImageToChain(theID)
theDoc2.AddBookmark(theSection, True)
End While
Dim cst = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("rooflightquotes.mdb")
Dim conn = CreateObject("ADODB.Connection")
conn.open(cst)
Session("myConn") = conn
dim rsAddquestion = Server.CreateObject("ADODB.Recordset")
strsql ="select * from pdfs where id=" & quotenumber & " "
rsAddquestion.Open(strsql, conn, 3, 3)
dim n as string
n=rsAddquestion.recordcount
rsAddquestion.AddNew
n=n+1
rsAddquestion("id")=quotenumber
rsAddquestion("pdfname") =quotenumber +"-rev"+n+".pdf"
rsAddquestion("printdate")=now()
rsAddquestion("status")="Printed"
rsAddquestion.update
rsAddquestion = Server.CreateObject("ADODB.Recordset")
strsql ="select * from header where id=" & quotenumber & " "
rsAddquestion.Open(strsql, conn, 3, 3)
rsAddquestion("status")="Printed"
rsAddquestion.update
conn.close
' add the pdf together in selected order
theDoc.Append(theDoc1)
theDoc.Append(theDoc1a)
theDoc.Append(theDoc2)
Dim theCount = theDoc.PageCount
' left bottom width heght
theDoc.Rect.String = "10 10 580 25"
theDoc.HPos = 1.0
theDoc.VPos = 0.5
theDoc.Color.String = "255 255 255"
theDoc.Font = theDoc.AddFont("Arial")
theDoc.FontSize = 10
For i = 1 To theCount
theDoc.PageNumber = i
If i <> 1 Then
theDoc.AddHtml(" Page " + i.ToString() + " of " + theCount.ToString() + "")
theDoc.FrameRect()
End If
Next
dim pdffilenamec = "pdf/"+quotenumber+"-rev"+n+".pdf"
theDoc.Save(Server.MapPath(pdffilenamec))
'response.redirect("rooflightquotepdfmenu.asp?quotenumber="+quotenumber)
End Sub
This used to work find in version 8, but not now using version 12

need help in correcting the Macro to filter the range and print

I am learning through the internet and based on my knowledge and data available on the internet, I have created the following macro which works. The purpose of the macro is to filter the data, arrange it in the desired format and print it.
The problem is, once I run the macro, all the filters are printed in one pass. I am looking for a change where after running the macro, I get a display to select the filter I want to print or if I want to print all the filters.
I hope I was able to explain my problem. Let me know if anyone can help me. Thanks
Sub itemno()
ThisWorkbook.Worksheets("Sheet1").Activate
Dim LR As Long
Dim Sh As Worksheet
Set Sh = Worksheets("Sheet1")
LR = Sh.Range("H" & Rows.Count).End(xlUp).Row
Sh.Range("P2:P" & LR).Formula = "=IF(LEFT(RC[-13],3)=""300"",RIGHT(RC[-7],4)&""-""&RIGHT(RC[-14],3),RC[-13])"
Sh.Range("P1:P" & LR).Copy
Sh.Columns("B:B").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sh.Columns("C:C").Delete
Sh.Columns("F:F").Delete
Sh.Columns("I:P").Delete
Sh.Range("A1").FormulaR1C1 = "Colli Nr."
Sh.Range("B1").FormulaR1C1 = "Item Nr."
Sh.Range("D1").FormulaR1C1 = "Unit"
Sh.Cells.Select
Sh.Cells.EntireColumn.Autofit
Sh.Columns("A:A").ColumnWidth = 20
Sh.Columns("C:C").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
End With
Selection.NumberFormat = "0.0"
Sh.Cells.Select
Selection.RowHeight = 25
With Selection
.VerticalAlignment = xlCenter
End With
Sh.Rows("1:1").Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Sh.Columns("F:F").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Sh.Range("F1").Select
ActiveCell.FormulaR1C1 = "Bemerkung"
Sh.Rows("1:1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Selection.Font.Bold = True
With Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Sh.Columns("E:E").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Sh.Range("E1").FormulaR1C1 = "CheckBox"
Sh.Range("M2:M" & LR).Formula = "=RC[-10]&"" ""&RC[-9]"
Sh.Range("M1:M" & LR).Copy
Sh.Columns("C:C").Select
Selection.PasteSpecial Paste:=xlPasteValues
Sh.Range("C1").FormulaR1C1 = "Menge"
Sh.Columns("M:M").Delete
Sh.Columns("D:D").Delete
Dim cb As CheckBox
Dim myRange As Range, cel As Range
Dim wks As Worksheet
Set wks = Sheets("Sheet1")
Set myRange = wks.Range("D2:D" & LR)
For Each cel In myRange
Set cb = wks.CheckBoxes.Add(cel.Left, cel.Top, 30, 15)
With cb
.Caption = ""
.OnAction = "ProcessCheckBox"
End With
Next
Dim Rang As Range
Set Rang = Sh.Range("A1:I" & LR)
With Rang.Borders
.LineStyle = xlContinuous
.Color = vbBlack
.Weight = xlThin
End With
wks.Rows("1:7").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.RowHeight = 15
Sh.Range("A1:F1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Sh.Range("A1:F1").Select
ActiveCell.FormulaR1C1 = "Packliste nur für die Werkstatt"
Sh.Range("A3").Select
ActiveCell.FormulaR1C1 = "Projekt:"
Sh.Range("B3:D3").Select
With Selection
.HorizontalAlignment = xlLeft
End With
Selection.Merge
Sh.Range("E3").Select
ActiveCell.FormulaR1C1 = "Column Nr."
Sh.Range("A4").Select
ActiveCell.FormulaR1C1 = "Zeichnung Nr. "
Sh.Range("B4:C4").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Sh.Range("E4").Select
ActiveCell.FormulaR1C1 = "Dokument Nr."
Sh.Range("A6").Select
ActiveCell.FormulaR1C1 = "Verpackt von:"
Sh.Range("E6").Select
ActiveCell.FormulaR1C1 = "Geprüft von:"
Sh.Rows("1:1").Select
Selection.RowHeight = 20
Selection.Font.Bold = True
Selection.Font.Size = 16
Selection.Font.Underline = xlUnderlineStyleSingle
Sh.Columns("B:B").ColumnWidth = 20
Sh.Columns("D:D").ColumnWidth = 15
Sh.Columns("C:C").ColumnWidth = 12
Sh.Columns("F:F").ColumnWidth = 40
Sh.Columns("G:G").Cut
Sh.Columns("J:J").Insert Shift:=xlToRight
Sh.Activate
Dim Rng As Range
Dim c As Range
Dim List As New Collection
Dim Item As Variant
Application.ScreenUpdating = False
Set Rng = Sh.Range("G9:G" & Sh.Range("G65536").End(xlUp).Row)
On Error Resume Next
For Each c In Rng
List.Add c.Value, CStr(c.Value)
Next c
On Error GoTo 0
Set Rng = Sh.Range("G8:G" & Sh.Range("G65536").End(xlUp).Row)
For Each Item In List
Rng.AutoFilter Field:=1, Criteria1:=Item
Sh.Range("F4") = Item
Sh.Range("F3:F4").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
End With
Sh.Range("F3").FormulaR1C1 = "=VLOOKUP(TEXT(R[1]C,0),C[1]:C[3],3,FALSE)"
Sh.Range("B4:C4").FormulaR1C1 = "=VLOOKUP(TEXT(RC[4],0),C[5]:C[7],2,FALSE)"
Sh.Range("B3:D3").FormulaR1C1 = "=LEFT(R[6]C,9)"
Application.PrintCommunication = False
Sh.Activate
ActiveSheet.PageSetup.PrintArea = "$A:$F"
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$8"
.LeftMargin = Application.InchesToPoints(0.236220472440945)
.RightMargin = Application.InchesToPoints(0.236220472440945)
.TopMargin = Application.InchesToPoints(0.2)
.BottomMargin = Application.InchesToPoints(0.35)
.HeaderMargin = Application.InchesToPoints(0.2)
.FooterMargin = Application.InchesToPoints(0.35)
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.LeftFooter = "Colli-Informationen eingeben (Abmessungen, Bruttogewicht & Tara)"
.RightFooter = "&P/&N"
End With
Application.PrintCommunication = True
Sh.PrintOut
Rng.AutoFilter
Next Item
Application.ScreenUpdating = True
End Sub

User inserting pictures in excel with macro

I'm a bit stuck on this one, since I couldn't find much on the web. Basically, I'd like the user to be able to click a button which formats some cells, and then opens a box which makes the user navigate through windows explorer in order to insert one or two pictures in the newly formatted cells.
This is what I have so far:
Private Sub AddPic_Click()
Dim lastCell As Range
Dim newCell1 As Range
Dim newCell2 As Range
Dim newCellMergePic1 As Range
Dim newCellMergePic2 As Range
Dim myRange As Range
Set myRange = Worksheets("Product Packaging").Range("A1:A1000")
For Each r In myRange
If r.MergeCells Then
Set lastCell = r
End If
Next r
Set newCell1 = lastCell.Offset(1, 0)
Set newCell2 = newCell1.Offset(0, 5)
Set newCellMergePic1 = Range(newCell1, newCell1.Offset(9, 4))
Set newCellMergePic2 = Range(newCell2, newCell2.Offset(9, 4))
newCellMergePic1.Merge
newCellMergePic2.Merge
With newCellMergePic1
.Font.Name = "Calibri"
.Font.Color = vbBlack
.VerticalAlignment = xlVAlignCenter
.HorizontalAlignment = xlHAlignCenter
.Font.Bold = True
.Value = "Picture Here"
End With
With newCellMergePic2
.Font.Name = "Calibri"
.Font.Color = vbBlack
.VerticalAlignment = xlVAlignCenter
.HorizontalAlignment = xlHAlignCenter
.Font.Bold = True
.Value = "Picture Here"
End With
End Sub
It works, but I don't know how to integrate the feature which allows the user to navigate through their folders in order to select the picture(s) they want to add. Thank you for the taking the time to read my post.
You will need to use a dialog box:
Option Explicit
Public Sub addImage1()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Ok"
.Title = "Select an image"
.Filters.Clear
.Filters.Add "JPG", "*.JPG"
.Filters.Add "JPEG File Interchange Format", "*.JPEG"
.Filters.Add "Graphics Interchange Format", "*.GIF"
.Filters.Add "Portable Network Graphics", "*.PNG"
.Filters.Add "All Pictures", "*.*"
If .Show = -1 Then
Dim img As Object
Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))
Else
MsgBox ("Cancelled.")
End If
End With
End Sub
or
Public Sub addImage2()
Dim result, imgTypes As String
imgTypes = imgTypes & "JPG files (*.jp*),*.jp*"
imgTypes = imgTypes & ", GIF files (*.gif),*.gif"
imgTypes = imgTypes & ", PNG files (*.png),*.png"
imgTypes = imgTypes & ", All files (*.*),*.*"
result = Application.GetOpenFilename(imgTypes, 1, "Select Image", , False)
If result <> False Then
ActiveSheet.Pictures.Insert (result)
End If
End Sub
Problem solved, here is the final result
Private Sub AddPic_Click()
Dim lastCell As Range
Dim newCell1 As Range
Dim newCell2 As Range
Dim newCellMergePic1 As Range
Dim newCellMergePic2 As Range
Dim myRange As Range
Dim fd As Office.FileDialog
Dim Pic1 As Picture
Dim Pic2 As Picture
Dim Pic1Path As String
Dim Pic2Path As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Set myRange = Worksheets("Product Packaging").Range("A1:A1000")
For Each r In myRange
If r.MergeCells Then
Set lastCell = r
End If
Next r
Set newCell1 = lastCell.Offset(1, 0)
Set newCell2 = newCell1.Offset(0, 5)
Set newCellMergePic1 = Range(newCell1, newCell1.Offset(9, 4))
Set newCellMergePic2 = Range(newCell2, newCell2.Offset(9, 4))
newCellMergePic1.Merge
newCellMergePic2.Merge
With newCellMergePic1
.Font.Name = "Calibri"
.Font.Color = vbBlack
.VerticalAlignment = xlVAlignCenter
.HorizontalAlignment = xlHAlignCenter
.Font.Bold = True
.Value = "Picture Here"
End With
With newCellMergePic2
.Font.Name = "Calibri"
.Font.Color = vbBlack
.VerticalAlignment = xlVAlignCenter
.HorizontalAlignment = xlHAlignCenter
.Font.Bold = True
.Value = "Picture Here"
End With
With fd
.AllowMultiSelect = True
.Title = "Please select picture(s). Maximum of two pictures per insert."
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
If .Show = True Then
If .SelectedItems.Count > 2 Then
MsgBox "Please select no more than 2 pictures at once.", vbExclamation, Conflict
Dim delRange1 As Excel.Range
Dim delRange2 As Excel.Range
Set myRange = Worksheets("Product Packaging").Range("A1:A1000")
For Each r In myRange
If r.MergeCells Then
Set lastCell = r
End If
Next r
If lastCell.Address <> Range("A2").Address Then
Set lastCell2 = lastCell.Offset(0, 5)
Set delRange1 = lastCell.MergeArea
Set delRange2 = lastCell2.MergeArea
delRange1.ClearContents
delRange2.ClearContents
lastCell.UnMerge
lastCell2.UnMerge
Exit Sub
End If
End If
Pic1Path = .SelectedItems(1)
Set Pic1 = Pictures.Insert(Pic1Path)
With Pic1.ShapeRange
.LockAspectRatio = msoTrue
.Height = newCellMergePic1.Height - 2
.Top = newCellMergePic1.Top + 1
.Left = newCellMergePic1.Left
End With
If .SelectedItems.Count = 2 Then
Pic2Path = .SelectedItems(2)
Set Pic2 = Pictures.Insert(Pic2Path)
With Pic2.ShapeRange
.LockAspectRatio = msoTrue
.Height = newCellMergePic2.Height - 2
.Top = newCellMergePic2.Top + 1
.Left = newCellMergePic2.Left
End With
End If
End If
End With
End Sub

Excel VBA - Apply auto filter and Sort by specific colour

I have an auto-filtered range of data. The auto filter was created by the following VB code:
Sub Colour_filter()
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.AutoFilter
End Sub
I would like to sort the values in column "A" (the data actually start from cell "A4") by the following colour ( Color = RGB(255, 102, 204) ) so all the cells with that colour sort to the top.
It would be fab if the extra code could be added to my existing code?
My office is really noisy and my VB isn’t the best. It is doubly hard with laughing, chatting ladies all about. Any help will be stress relief heaven!! (p.s. no poke at the ladies it’s just my office is 95% women).
Edited per request by #ScottHoltzman.
My requested code forms part of a larger code which would confuse matters, although here is a slimmed down version of the aspect I currently need.
Sub Colour_filter()
' Following code( using conditional formatting) adds highlight to 'excluded' courses based
'on 'course code' cell value matching criteria. Courses codes matching criteria are highlighted
'in 'Pink'; as of 19-Nov-2012 the 'excluded' course codes are
'(BIGTEST, BIGFATCAT).
' <====== CONDITIONAL FORMATTING CODE STARTS HERE =======>
Columns("A:A").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""BIGTEST"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = 13395711
End With
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""BIGFATCAT"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = 13395711
End With
' <====== CONDITIONAL FORMATTING CODE ENDS HERE =======>
' Following code returns column A:A to Font "Tahoma", Size "8"
Columns("A:A").Select
With Selection.Font
.Name = "Tahoma"
.FontStyle = "Regular"
.Size = 8
.ThemeColor = xlThemeColorLight1
.ThemeFont = xlThemeFontNone
End With
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = False
End With
' Following code adds border around all contiguous cells ion range, similar to using keyboard short cut "Ctrl + A".
Range("A4").Select
ActiveCell.CurrentRegion.Select
With Selection
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
' Following code adds 'Blue' cell colour to all headers in Row 4 start in Cell "A4".
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.Font.Bold = True
'<== adds auto-filter to my range of cells ===>
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.AutoFilter
End Sub
Well here is a small Sub that does the following sorting as per shown image. Most of the values like dimensions/range sizes are very static since this is a sample. You may improve it to be dynamic. Please comment if this code is going in the right direction so I can update with the final sort.
EDITTED CODE WITH DOUBLE SORT KYES
code:
Option Explicit
Sub sortByColor()
Dim rng As Range
Dim i As Integer
Dim inputArray As Variant, colourSortID As Variant
Dim colourIndex As Long
Set rng = Sheets(1).Range("D2:D13")
colourIndex = Sheets(1).Range("G2").Interior.colorIndex
ReDim inputArray(1 To 12)
ReDim colourSortID(1 To 12)
For i = 1 To 12
inputArray(i) = rng.Cells(i, 1).Interior.colorIndex
If inputArray(i) = colourIndex Then
colourSortID(i) = 1
Else
colourSortID(i) = 0
End If
Next i
'--output the array with colourIndexvalues and sorting key values
Sheets(1).Range("E2").Resize(UBound(inputArray) + 1) = _
Application.Transpose(inputArray)
Sheets(1).Range("F2").Resize(UBound(colourSortID) + 1) = _
Application.Transpose(colourSortID)
'-sort the rows based on the interior colour
Application.DisplayAlerts = False
Set rng = rng.Resize(, 3)
rng.Sort Key1:=Range("F2"), Order1:=xlDescending, _
Key2:=Range("E2"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.DisplayAlerts = True
End Sub
output:

Why is my code Selecting & Hightlighting more than 1 row in my MshFlexgrid?

I have a VB6 project that is using a SQL2008 database. The project consists of two Combo Boxes , a MSHFlexGrid, and Two Command Buttons(cmdLoadSeries & cmdExit). The user will make a selection from the first Combo box and press the cmdLoadSeries command button which populates the 2nd combo box and the MSHFlexgrid. I am using a text box to manipulate the info in the grid.
The First time I select a line in the mshflexgrid it selects/Highlights the row i clicked on and everything above it as well. After the first time, it only selects/highlights the row I clicked on. Why? Please help.
Here is my code:
Private Sub cmdLoadSeries_Click()
Const cProcName = msModuleName & "cmdLoadSeries"
'Too save space I removed the code that retrieves MRecordSet.
If mRecordSet.RecordCount > 0 Then
LoadControls
SetFormFields True
DataCombo1.BoundText = mRecordSet2.Fields(0)
Else
LoadControls
cmdExit.Enabled = True
End If
cmdLoadSeries.Enabled = False
Combo1.Enabled = False
End Sub
Private Sub LoadControls()
Const cProcName = msModuleName & "LoadControls"
With mRecordSet
OpenRSFlexGrid1
FillFlexGrid1
End With
End Sub
Sub OpenRSFlexGrid1
'This code setups a recordset used to populate the mshflexgrid with
End Sub
Sub FillFlexGrid1(Optional pbClear As Boolean)
Const cProcName = msModuleName & "FillFlexGrid1"
Dim llCntrRow As Integer
Dim llCntrCol As Integer
Dim max_len As Single
Dim new_len As Single
Dim liCntr As Integer
Dim llCol As Long
Text1.BorderStyle = 0
With MSFlexGrid1
MSFlexGrid1.Clear
Text1.FontName = .FontName
Text1.FontSize = .FontSize
Text1.Visible = False
.Cols = mRecordset4.Fields.Count
.FixedCols = 1
If mRecordset4.RecordCount > 0 And (Not pbClear = True) Then
.Rows = mRecordset4.RecordCount + 1
.FixedRows = 1
Else
.Rows = 2
.FixedRows = 1
End If
For llCntrCol = 0 To .Cols - 1
.TextMatrix(0, llCntrCol) = mRecordset4.Fields(llCntrCol).Name
Next
If mRecordset4.RecordCount > 0 And (Not pbClear = True) Then
mRecordset4.MoveFirst
For llCntrRow = 1 To mRecordset4.RecordCount
For llCntrCol = 0 To .Cols - 1
.TextMatrix(llCntrRow, llCntrCol) = Trim(CStr(mRecordset4.Fields(llCntrCol).Value))
Next
mRecordset4.MoveNext
Next
Else
For llCntrCol = 0 To .Cols - 1
.TextMatrix(.FixedRows, llCntrCol) = ""
Next
End If
Font.Name = MSFlexGrid1.Font.Name
Font.Size = MSFlexGrid1.Font.Size
For llCntrCol = 0 To MSFlexGrid1.Cols - 1
max_len = 0
If .TextMatrix(0, llCntrCol) = "setoutid" Then
MSFlexGrid1.ColWidth(llCntrCol) = TextWidth("W") * 0.54
Else
For llCntrRow = 0 To MSFlexGrid1.Rows - 1
new_len = TextWidth(MSFlexGrid1.TextMatrix(llCntrRow, llCntrCol))
If max_len < new_len Then max_len = new_len
Next llCntrRow
Dim lsFillColumn As String
lsFillColumn = String(42, "W")
If .TextMatrix(0, llCntrCol) = "setoutname" And TextWidth(lsFillColumn) > max_len Then
max_len = TextWidth(lsFillColumn)
End If
MSFlexGrid1.ColWidth(llCntrCol) = max_len + (TextWidth("W") * 1.5)
MSFlexGrid1.ColAlignment(llCntrCol) = flexAlignLeftCenter
End If
Next llCntrCol
.Col = .FixedCols
.Row = .FixedRows
End With
Exit Sub
errFillFlexGrid1:
Resume Next
End Sub
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
Const cProcName = msModuleName & "MSFlexGrid1_KeyDown"
On Error GoTo errhandle
With MSFlexGrid1
If Text1.Visible = False Then
Select Case KeyCode
Case 45
If Shift = 1 Then
.AddItem "", .Row + 1
Else
.AddItem "", .Row
End If
mbFlexGrid1Changed = True
Case 46
If MSFlexGrid1.Rows = .FixedRows + 1 Then
MSFlexGrid1.Rows = MSFlexGrid1.Rows + .FixedRows - 1
Else
.RemoveItem .Row
End If
mbFlexGrid1Changed = True
End Select
End If
End With
Exit Sub
errhandle:
Resume Next
End Sub
Private Sub Text1_LostFocus()
Const cProcName = msModuleName & "Text1_LostFocus"
On Error GoTo errhandle
If Text1.Visible Then
MSFlexGrid1.Text = Text1.Text
End If
Text1.Visible = False
Exit Sub
errhandle:
Resume Next
End Sub
Private Sub MSFlexGrid1_GotFocus()
Const cProcName = msModuleName & "MSFlexGrid1_GotFocus"
On Error GoTo errhandle
bLostFocus = False
pSetTabStop (True)
If mlCurrentCol > 0 Then
MSFlexGrid1.Col = mlCurrentCol
MSFlexGrid1.Row = mlCurrentRow
End If
mlCurrentCol = 0
mlCurrentRow = 0
If Text1.Visible Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible = False
End If
Exit Sub
errhandle:
Resume Next
End Sub
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
Const cProcName = msModuleName & "MSFlexGrid1_KeyPress"
On Error GoTo errhandle
Select Case KeyAscii
Case 27
If Text1.Visible Then
Text1.Visible = False
End If
Case Else
FlexGridEdit KeyAscii
End Select
Exit Sub
errhandle:
Resume Next
End Sub
Private Sub MSFlexGrid1_LeaveCell()
Const cProcName = msModuleName & "MSFlexGrid1_LeaveCell"
On Error GoTo errhandle
If Text1.Visible Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible = False
End If
Exit Sub
errhandle:
Resume Next
End Sub
Private Function FlexGridChkPos(KeyCode As Integer) As Boolean
Dim llNextRow As Long
Dim llNextCol As Long
Dim llCurrCol As Long
Dim llCurrRow As Long
Dim llTotCols As Long
Dim llTotRows As Long
Dim llBegRow As Long
Dim llBegCol As Long
Dim llCntrCol As Long
Dim lsText As String
Const cProcName = msModuleName & "FlexGridChkPos"
On Error GoTo errhandle
With MSFlexGrid1
llCurrRow = .Row + 1
llCurrCol = .Col + 1
llTotRows = .Rows
llTotCols = .Cols
llBegRow = .FixedRows
llBegCol = .FixedCols
If KeyCode = vbKeyRight Or KeyCode = vbKeyReturn Then
llNextCol = llCurrCol + 1
If llNextCol > llTotCols Then
llNextRow = llCurrRow + 1
If llNextRow > llTotRows Then
GoSub LogLine
.Rows = .Rows + 1
llCurrRow = llCurrRow + 1
llCurrCol = 1 + llBegCol
Else
llCurrRow = llNextRow
llCurrCol = 1 + llBegCol
End If
Else
llCurrCol = llNextCol
End If
End If
If KeyCode = vbKeyLeft Then
llNextCol = llCurrCol - 1
If llNextCol = llBegCol Then
llNextRow = llCurrRow - 1
If llNextRow = llBegRow Then
llCurrRow = llTotRows
Else
llCurrRow = llNextRow
End If
llCurrCol = llTotCols
Else
llCurrCol = llNextCol
End If
End If
.Col = llCurrCol - 1
.Row = llCurrRow - 1
End With
Exit Function
LogLine:
lsText = ""
Return
errhandle:
Resume Next
End Function
The .row parameter was not being set correctly upon first entering the grid.

Resources