Solved

excel question

Posted on 1998-08-16
2
677 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 100 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 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