Solved

excel question

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 79
to transfer string from C lanaguage to VBA 4 66
Copy a row 12 62
Visual Studio search word table and return Cell index 8 61
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 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