Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

excel question

Posted on 1998-08-16
2
Medium Priority
?
682 Views
Last Modified: 2008-02-01
Option Explicit
Dim ws As Workspace
Dim Excelsheet As Object
Dim Worksheets
Dim Worksheet As Integer
Dim sSql$

Private Sub cmdPrint_Click()

Dim iRCnt%
Dim db As Database
Dim rs As Recordset
Dim n As Integer
Dim XName1, XName2, XName3, XName4, XName5, XName6, XName7, XName8, XName9, XName10 As String
Dim numcopies As Integer

Set Excelsheet = CreateObject("Excel.sheet")
Worksheet = 1


If txtStockNo.Text = "" Then
  MsgBox "Please enter a stockno to print"
  Exit Sub
End If


If CheckExists(Val(txtStockNo.Text)) = True Then

Set ws = Workspaces(0)
Set db = OpenDatabase("c:\stock.mdb")

sSql = "select * from Description, Product, Received_On, Issued_On, Balance where  " _
      + "val(Description.StockCardNo) = """ & Val(txtStockNo) & """ " _
      & "and Description.StockCardNo = Product.StockCardNo and Product.ProductID = Received_On.ProductID and Received_On.ProductID = Issued_On.ProductID and Received_On.ProductID = Balance.ProductID order by Product.ProductID and Description.StockCardNo "

' & "and Product.Specifications = '" + txtSpecs.Text + "' " _

Set rs = db.OpenRecordset(sSql)


Set DtaPrint.Recordset = rs
rs.MoveLast
iRCnt = rs.RecordCount

With Excelsheet
 If Worksheet > 1 Then
   .Worksheets.Add
   .Worksheets.PageSetup.LeftMargin = .Application.InchesToPoints(0.25)
   .Worksheets.RightMargin = .Application.InchesToPoints(0.25)
   .Worksheets.TopMargin = .Application.InchesToPoints(1)
   .Worksheets.BottomMargin = .Application.InchesToPoints(1)
   .Worksheets.HeaderMargin = .Application.InchesToPoints(0.5)
   .Worksheets.FooterMargin = .Application.InchesToPoints(0.5)
   
 End If

.Application.Visible = True


If iRCnt = 0 Then Exit Sub

.Worksheets(1).PageSetup.LeftMargin = .Application.InchesToPoints(0.25)
.Worksheets(1).PageSetup.RightMargin = .Application.InchesToPoints(0.25)
.Worksheets(1).PageSetup.TopMargin = .Application.InchesToPoints(1)
.Worksheets(1).PageSetup.BottomMargin = .Application.InchesToPoints(1)
.Worksheets(1).PageSetup.HeaderMargin = .Application.InchesToPoints(0.5)
.Worksheets(1).PageSetup.FooterMargin = .Application.InchesToPoints(0.5)

.Worksheets(1).range("D2").Value = "Mathematics, Science & Computing Center"
.Worksheets(1).range("D2").Font.fontstyle = "Bold"
'.Worksheets(1).range("D2").HorizontalAlignment = xlCenter
 
.Worksheets(1).range("D2").shrinktofit = False

.Worksheets(1).range("H2").Value = "MSC"
.Worksheets(1).range("H2").Font.fontstyle = "Bold"
'.Worksheets(1).range("H2").HorizontalAlignment = xlCenter

.Worksheets(1).range("I2").Value = txtStockNo.Text

.Worksheets(1).range("D3").Value = "Stock Record Card"
.Worksheets(1).range("D3").Font.fontstyle = "Bold"
'.Worksheets(1).range("D3").HorizontalAlignment = xlCenter

.Worksheets(1).range("A5").Value = "Description"
.Worksheets(1).range("B5").Value = GetDesc(Val(txtStockNo))

.Worksheets(1).range("C7").Value = "Receipts"
'.Worksheets(1).range("C7").HorizontalAlignment = xlCenter

.Worksheets(1).range("G7").Value = "Issues"
.Worksheets(1).range("I7").Value = "Balance"
.Worksheets(1).range("J7").Value = "Remarks"

.Worksheets(1).range("A8").Value = "Date"
'.Worksheets(1).range("A8").HorizontalAlignment = xlCenter

.Worksheets(1).range("B8").Value = "Type"
'.Worksheets(1).range("B8").HorizontalAlignment = xlCenter

.Worksheets(1).range("C8").Value = "Bill/PO"
'.Worksheets(1).range("C8").HorizontalAlignment = xlCenter

.Worksheets(1).range("D8").Value = "Qty"
'.Worksheets(1).range("D8").HorizontalAlignment = xlCenter

.Worksheets(1).range("E8").Value = "U/Price"
'.Worksheets(1).range("E8").HorizontalAlignment = xlCenter

.Worksheets(1).range("F8").Value = "Date"
'.Worksheets(1).range("F8").HorizontalAlignment = xlCenter

.Worksheets(1).range("G8").Value = "Req/Loc"
'.Worksheets(1).range("G8").HorizontalAlignment = xlCenter

.Worksheets(1).range("H8").Value = "Qty"
'.Worksheets(1).range("H8").HorizontalAlignment = xlCenter

.Worksheets(1).range("I8").Value = "Qty"
'.Worksheets(1).range("I8").HorizontalAlignment = xlCenter

'.Worksheets(1).range("G8").Borders.LineStyle = xlContinuous
'.Worksheets(1).range("G8").Borders.ColorIndex = xlAutomatic
.Worksheets(1).range("H5").Borders.LineStyle = xlContinuous
.Worksheets(1).range("H5").Borders.ColorIndex = xlAutomatic

rs.MoveFirst

For n = 0 To iRCnt - 1
 XName1 = "A" + Format(n + 10)
 XName2 = "B" + Format(n + 10)
 XName3 = "C" + Format(n + 10)
 XName4 = "D" + Format(n + 10)
 XName5 = "E" + Format(n + 10)
 XName6 = "F" + Format(n + 10)
 XName7 = "G" + Format(n + 10)
 XName8 = "H" + Format(n + 10)
 XName9 = "I" + Format(n + 10)
 XName10 = "J" + Format(n + 10)
 
 
.Worksheets(1).range(XName1).Value = rs.Fields("DateReceived")
.Worksheets(1).range(XName2).Value = rs.Fields("Specifications")
.Worksheets(1).range(XName3).Value = rs.Fields("BillNumber")
.Worksheets(1).range(XName4).Value = rs.Fields("QtyReceived")
.Worksheets(1).range(XName5).Value = rs.Fields("UnitPrice")
.Worksheets(1).range(XName6).Value = rs.Fields("DateIssued")
.Worksheets(1).range(XName7).Value = rs.Fields("Requisitioner")
.Worksheets(1).range(XName8).Value = rs.Fields("QtyIssued")
.Worksheets(1).range(XName9).Value = rs.Fields("QuantityLeft")
.Worksheets(1).range(XName10).Value = rs.Fields("Remarks")



.Worksheets(1).range(XName1).Select
.Worksheets(1).range(XName1).NumberFormat = "dd/mm/yy"

.Worksheets(1).range(XName6).Select
.Worksheets(1).range(XName6).NumberFormat = "dd/mm/yy"

.Worksheets(1).range(XName5).Select
.Worksheets(1).range(XName5).NumberFormat = "$#,##0.00;[Red]$#,##0.00"

.Worksheets(1).Columns("A:A").columnwidth = 7.14
.Worksheets(1).Columns("B:B").columnwidth = 11.86
.Worksheets(1).Columns("C:C").columnwidth = 11.29
.Worksheets(1).Columns("D:D").columnwidth = 4
.Worksheets(1).Columns("E:E").columnwidth = 7.29
.Worksheets(1).Columns("F:F").columnwidth = 7.43
.Worksheets(1).Columns("G:G").columnwidth = 14.86
.Worksheets(1).Columns("H:H").columnwidth = 4.29
.Worksheets(1).Columns("I:I").columnwidth = 6.86
.Worksheets(1).Columns("J:J").columnwidth = 17

rs.MoveNext
Next n

numcopies = 1

Worksheet = Worksheet + 1

Excelsheet.SaveAs "c:\Bookie.xls"
'Excelsheet.printout , , numcopies
Excelsheet.Application.Quit
'Kill "c:\Bookie.xls"

Set Excelsheet = Nothing

End With
     
End If

 
     
     
End Sub




i tried worksheets(!).range("A2").select.horizontalAlignment = xlCenter
and it said xlCenter is a undefine variable
also xlcontinous and xlautomatic is undefine...
can anyone solve this problem?
0
Comment
Question by:nightrage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
lbk earned 200 total points
ID: 1429130
This is quite a bit of code, and I doubt to have the time to go through all of it, but considering you're late binding excel objects, it seem you didn't reference the Excel object library, which would indeed result in enumeration being unknown.

Try referencing the Excel object library... good luck

PS, once you did, you won't need createobject() anymore, but can use NEW WorkSheet instead, etc
0
 
LVL 3

Expert Comment

by:frazer
ID: 1429131
Hi,

Dim XName1, XName2, XName3, XName4, XName5, XName6, XName7, XName8, XName9, XName10 As String

note:- in the above line, i am guessing that you want all variables to be strings....

The way you are declaring them all are variants except XName10

You must declare each variable individually.

You can use the shortcuts..

i.e.

&=Long
$=String
%=Integer.....

Hope this helps

Frazer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question