Creating Labels in VB
the following is what i am trying to do:
Read 1st record
Save the 1st record (box#) in a variable
Print box#
Print Gf#
Read Next
If box# saved? if yes then go back to print gf. if no then move to next record and go back to the save the 2nd record (box#) in a variable
this is what i have so far:
Dim labelApp As Word.Application
Dim labelDoc As Word.Document
Dim skip As Boolean
Dim madenew As Boolean
Dim newone As String
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim boxno as String
'Start a new document in Word
Set labelApp = CreateObject("Word.application")
Set labelDoc = labelApp.Documents.Add
madnew = False
If labelApp.Documents.Count = 0 Then
labelApp.Documents.Add
madenew = True
newone = labelDoc.Name
End If
labelApp.MailingLabel.DefaultPrintBarCode = False
labelApp.MailingLabel.CreateNewDocument Name:="5163", Address:="", _
Autotext:="toolscreatelabels1", lasertray:=wdPrinterManualFeed, _
extractaddress:=False, printEpostagelabel:=False, Vertical:=False
skip = True
conn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ETC;Data Source=PHNOTES01"
boxno = InputBox("Type the box# you want labels for.")
rs.Open "SELECT * FROM ETCLog WHERE box# = " & boxno, conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
rs.MoveFirst
boxno = boxno
Selection.Font.Underline = wdUnderlineSingle
Selection.Font.Bold = True
Selection.Font.Name = "Arial Bold"
Selection.Font.Size = 14
Selection.TypeText Text:="Box#: " & rs!box#
Selection.TypeParagraph
If rs!box# = boxno Then
Selection.TypeText Text:=rs!gf#
Else
rs.MoveNext
Selection.MoveRight unit:=wdCell
If skip Then
Selection.MoveRight unit:=wdCell
skip = False
Else
skip = True
End If
End If
End If
i get an error at the highlighted above saying: object variable or with block variable not set and i put the with and end with in but then i get and error at rs!box# saying method or data member not found. not sure what i am doing wrong
am i missing something or doing this all wrong?
|