How to initialize a chart with data in MS Access VBA? Eventually I found a suggestion here which with a bit of modification kept intellisense happy and resulted in this code:
Dim objchart As Chart
Dim arrData(3, 1) As Double
arrData(0, 0) = 1
arrData(1, 0) = 1
arrData(2, 0) = 1
arrData(3, 0) = 1
arrData(0, 1) = 1
arrData(1, 1) = 1
arrData(2, 1) = 1
arrData(3, 1) = 1
Set objchart = Me.Chart1
With objchart
.ChartTitle = "test"
.ChartType = acChartLine
.ChartValues = arrData
End With
But this throws
Compile error: Type mismatch
on the line
.ChartValues = arrData
I have tried it as "row-first" (arrData(1, 3)) and also just passing in a single array (arrData(3)). These both result in the same type mismatch error. While the intellisense is telling me that Chart1 exists, and that .ChartValues is a valid field, it doesn't tell me what kind of object it is expecting. I have googled extensively on this and come up empty. The best references I could find for Access VBA were Building VBA Apps and this but neither go into detail on Charts or ChartObjects.
Obviously I'd like to get past this type mismatch error. Even better would be if someone can give me some general advice on how to go about this when the closest thing to a language reference is silent on the part of the language you need.
This is one way to do it. First, create a new table and add some data:
Private Sub Form_Load()
Dim db As DAO.Database
Dim rec As Recordset
Dim tbl As DAO.TableDef
Set db = CurrentDb
Set tbl = db.CreateTableDef("tbl")
With tbl
.Fields.Append .CreateField("first", dbInteger)
.Fields.Append .CreateField("second", dbInteger)
End With
db.TableDefs.Append tbl
db.TableDefs.Refresh
Set rec = db.OpenRecordset("tbl")
rec.AddNew
rec("first").Value = 0
rec("second").Value = 2
rec.Update
rec.AddNew
rec("first").Value = 1
rec("second").Value = 2
rec.Update
rec.AddNew
rec("first").Value = 2
rec("second").Value = 2
rec.Update
rec.AddNew
rec("first").Value = 3
rec("second").Value = 2
rec.Update
Set rec = Nothing
Set db = Nothing
End Sub
Second, graph that data by referencing the new table:
Private Sub command0_click()
Dim objchart As Chart
Set objchart = Me.Chart1
With objchart
.ChartTitle = "tbl: second ~ first"
.RowSource = "tbl"
.ChartAxis = "first"
.ChartValues = "second"
End With
End Sub
Related
Okay i would like to be able to update part attributes table from a form. The Part_ID in table (primary key) is listed in combo box in form (prtnum_cbo) this carries a list of attributes that can be loaded into form, from the table SawPartNumber. I found code that works to Add a new record to table below. But I can not find anything on how to update or edit the record in table linked to Part_ID / prtnum_cbo. Using same logic as add new i can edit.. but only the 1st record in table updates
Private Sub svprt_cmd_Click()
On Error GoTo Error_Handler
Dim db As Database
Dim rec As Recordset
Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from SawPartNumber")
rec.AddNew
rec("Part_ID") = Me.prtnum_cbo
rec("Rev") = Me.rev_txt
rec("Tool Type") = Me.tool_cbo
rec("Tool Diameter") = Me.TDia_txt
rec("Wing count") = Me.tip_cnt_txt
rec("Saw Style") = Me.styl_cbo
rec("Kerf") = Me.kerf_txt
rec("Tip style") = Me.tips_cbo
rec("Tip grade") = Me.tipg_txt
rec("Hook") = Me.hook_txt
rec("OD cl") = Me.odcl_txt
rec("Radial") = Me.radin_txt
rec("Back") = Me.backin_txt
rec("Drop") = Me.drop_txt
rec("Top Bvl") = Me.tpbvl_txt
rec("Cnr Brk") = Me.cnrbk_txt
rec("K Lnd") = Me.klnd_txt
rec("Tooth Style Count") = Me.tscnt_txt
rec("Special Notes") = Me.prtnts_txt
rec("Tooth style") = Me.toos_txt
rec.Update
Set rec = Nothing
Set db = Nothing
Error_Handler_Exit:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "Part already exists"
Resume Error_Handler_Exit
End Sub
I have a LIST which contains many record's, I want to extract records based on a condition and if the condition satisfies then I need to add the condition satisfied record into a new list.
Below is the code which I have written till now:
Module Module2
Sub Main()
Dim td
td = CreateObject("TDApiOle80.TDConnection")
td.InitConnectionEx("http://qc10dev/qcbin")
'Note: For Quality Center, connect by using the URL below:
'td.InitConnectionEx "http://<servername>:port/qcbin"
td.ConnectProjectEx("DEFAULT", "GPS_PROGRAM", "PQRST", "XYX#123")
Dim tsfact 'As TDAPIOLELib.TestSetFactory
Dim tslist 'As TDAPIOLELib.List
'Getting Random Test Set ID
'************************ACCESS ALL THE TEST SETS ******************************************************************** '
tsfact = td.TestSetFactory
tslist = tsfact.NewList("")
'************************GET THE COUNT OF TEST SETS ******************************************************************
Dim Count_Of_TestSets
Count_Of_TestSets = tslist.Count
Console.WriteLine("Count of Test Sets" + Count_Of_TestSets.ToString)
'************************GET A RANDOM TEST SET INDEX ***************************************************************
Dim TestSetID As Integer
Dim TestSetName = Nothing
Dim SerialNumber As Integer = 0
Dim AttachmentPresent
Dim tslist_Having_Attachments = Nothing
For Each TestSet In tslist
TestSetID = TestSet.ID
TestSetName = TestSet.Name
'Console.WriteLine("TestSet ID::" + TestSetID.ToString() + "Test Set Name" + TestSetName)
AttachmentPresent = TestSet.HasAttachment()
If StrComp(AttachmentPresent, "True") = 0 Then
Console.WriteLine("TestSet ID::" + TestSetID.ToString() + "Test Set Name" + TestSetName)
End If
Next
Console.WriteLine("Logic Completed, Press enter")
Console.ReadLine()
tslist = Nothing
tsfact = Nothing
td = Nothing
End Sub
End Module
If you go through the above code the base List is tslist.
From this tslist which ever records has satisfied condition StrComp(AttachmentPresent, "True") = 0
has to be added to New list say tslist_attachment.
How can create a new list and add the values?
Please let me know the steps,.
Regards,
Srihari
From your description, it seems that you want to have a list of all attachments. You want to do that by iterating the TestSet, see if it contains an attachment and if so, add it to a list.
This post on SQA Forums explains how you can directly retrieve the list of attachments from a given testset by using the TestSetTreeManager and retrieving a TestSet from it by node id. Then all attachment from this node can be gathered at once:
Snippet:
Set TestSetTreeManager = TDConnection.TestSetTreeManager
Set TestSetFolder = TestSetTreeManager.NodeById(provideId)
If TestSetFolder.HasAttachments Then
Set Attachment = TestSetFolder.Attachments
Set AttachmentList = Attachment.NewList(" ")
End if
Below is the Logic I have written to handle this :)
Module Module2
Sub Main()
Dim td
td = CreateObject("TDApiOle80.TDConnection")
td.InitConnectionEx("http://qc10dev/qcbin")
'Note: For Quality Center, connect by using the URL below:
'td.InitConnectionEx "http://<servername>:port/qcbin"
td.ConnectProjectEx("DEFAULT", "GPS_PROGRAM", "svanumu", "ABCD")
Dim tsfact As TDAPIOLELib.TestSetFactory
Dim tslist As TDAPIOLELib.List
Dim Temporary_List As TDAPIOLELib.List = Nothing
Temporary_List = New TDAPIOLELib.List()
'Getting Random Test Set ID
'************************ACCESS ALL THE TEST SETS ******************************************************************** '
tsfact = td.TestSetFactory
tslist = tsfact.NewList("")
'************************GET THE COUNT OF TEST SETS ******************************************************************
Dim Count_Of_TestSets
Count_Of_TestSets = tslist.Count
Console.WriteLine("Count of Test Sets" + Count_Of_TestSets.ToString)
'************************GET A RANDOM TEST SET INDEX ***************************************************************
Dim TestSetID As Integer
Dim TestSetName = Nothing
Dim SerialNumber As Integer = 0
Dim AttachmentPresent
'Dim tslist_Having_Attachments As TDAPIOLELib.TestSetFactory
Dim TestSetID1 = Nothing
Dim TestSetName1 = Nothing
For Each TestSet In tslist
TestSetID = TestSet.ID
TestSetName = TestSet.Name
AttachmentPresent = TestSet.HasAttachment()
If StrComp(AttachmentPresent, "True") = 0 Then
Temporary_List.Add(TestSet)
'Console.WriteLine("TestSetID::" + TestSetID.ToString + "TestSetName::" + TestSetName + "is Added from temporary list")
End If
Next
'************************GET THE COUNT OF TEST SETS IN THE TEMPORARY LIST ******************************************************************
Dim Count_Of_TestSets_In_Temporary_List
Count_Of_TestSets_In_Temporary_List = Temporary_List.Count
Console.WriteLine("Count_Of_TestSets_In_Temporary_List" + Count_Of_TestSets_In_Temporary_List.ToString)
Console.WriteLine("Logic Completed, Press enter")
Console.ReadLine()
tslist = Nothing
tsfact = Nothing
td = Nothing
End Sub
End Module
Regards,
Srihari
I want to call an ABAP function from an Excel VBA Macro.
Is there any method I can follow to achieve this.
Please help me regarding this.
Dim sapConn As Object 'Declare connection object
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
sapConn.Connection.user = "user" 'Specify user
sapConn.Connection.Password = "" 'Then password
sapConn.Connection.client = "001" 'Client
sapConn.Connection.ApplicationServer = "server" 'Target server address
sapConn.Connection.Language = "PT" 'Language code
'Finally, try to logon to the specified system and check if the connection established
If sapConn.Connection.Logon(0, True) <> True Then
MsgBox "Cannot Log on to SAP" 'Issue message if cannot logon
Else
MsgBox "Logged on to SAP!"
End If
Dim rfcAcctDocCheck As Object
Dim oAcctHeader As Object
Dim otAcctAR, otAcctGL, otAcctAP, otAcctAMT, otReturn As Object
Set rfcAcctDocCheck = sapConn.Add("BAPI_ACC_DOCUMENT_CHECK")
Set oAcctHeader = rfcAcctDocCheck.Exports("DOCUMENTHEADER")
Set otAcctGL = rfcAcctDocCheck.Tables("ACCOUNTGL")
Set otAcctAR = rfcAcctDocCheck.Tables("ACCOUNTRECEIVABLE")
Set otAcctAP = rfcAcctDocCheck.Tables("ACCOUNTPAYABLE")
Set otAcctAMT = rfcAcctDocCheck.Tables("CURRENCYAMOUNT")
Set otReturn = rfcAcctDocCheck.Tables("RETURN")
Dim qtLegs As Integer
Dim dt, comp, tpDoc, docRef, tpAcct, acct, customer, vendor, _
curr, val, spLedger, ccenter, order As String
Dim curLine As Integer
For lin = 1 To UBound(reg)
id = Format(tbPost.Cells(reg(lin).lin_ini, K_COL_ID), "0000000000")
dt = getDate(tbPost.Cells(reg(lin).lin_ini, K_COL_DT))
comp = getCompanyCode(tbPost.Cells(reg(lin).lin_ini, K_COL_EMPR))
tpDoc = getDocumentType(tbPost.Cells(reg(lin).lin_ini, K_COL_TP_DOC))
docRef = tbPost.Cells(reg(lin).lin_ini, K_COL_DOC_REF)
otAcctGL.freeTable
otAcctAR.freeTable
otAcctAP.freeTable
otAcctAMT.freeTable
oAcctHeader("USERNAME") = sapConn.Connection.user
oAcctHeader("HEADER_TXT") = "Lancado via Excel"
oAcctHeader("COMP_CODE") = comp
oAcctHeader("DOC_DATE") = dt
oAcctHeader("PSTNG_DATE") = dt
oAcctHeader("DOC_TYPE") = tpDoc
oAcctHeader("REF_DOC_NO") = docRef
otAcctAMT.Rows.Add
otAcctAMT(otAcctAMT.Rows.Count, "ITEMNO_ACC") = Format(leg, "0000000000")
otAcctAMT(otAcctAMT.Rows.Count, "CURRENCY") = curr
otAcctAMT(otAcctAMT.Rows.Count, "AMT_BASE") = val
Next
If rfcAcctDocCheck.Call = False Then
MsgBox rfcAcctDocCheck.Exception
End If
I currently have a form in access.
What I want to do is get the value of the last record added.
For example, if i have 10 records, I want to get the value "10", because this is the id of the added last record. I am trying to run a query with the function last id inserted() but it is not working.
This the code I am using :
Dim lastID As Integer
Query = "select last_insert_id()"
lastID = Query
MsgBox (lastID)
What am I missing?
There is a function DMax that will grab the highest number.
Dim lastID As Integer
lastID = DMax("IDField","YourTable")
' or = DMax("IDField","YourTable","WhenField=Value")
MsgBox lastID
The other Domain functions are:
DAvg
DCount
DFirst
DLast
DLookup
DMin
DStDev
DStDevP
DSum
DVar
DVarP
Check with your friendly F1 key for more info
Following on from the last comments, here's a piece of code I used recently to turn the last ID value of a record set into variable for use in VBA. It's not great, however, because I still can't work out how to turn the record's ID field value directly into a variable. Instead I used the inelegant solution of copying the record set into an excel workbook, and then setting the variable value to the value of the cell I just copied into.
EDIT: Worked out how to turn the ID into a simple variable: new code at end
This is all run from a single client workbook:
Option Explicit
Public AftUpD As Long
Public BfrUpD As Long
Sub AssignLstRowAftUpD2()
Dim dbPP As DAO.Database
Dim ResTemp As DAO.Recordset
Dim z As Long
Dim SelectLast As String
SelectLast = "SELECT Max(Table1.ID) AS MaxOfID FROM Table1"
'Debug.Print SelectLast
Set dbPP = OpenDatabase("C:\filepath\Database11.mdb")
Set ResTemp = dbPP.OpenRecordset(SelectLast)
If ResTemp.EOF Then
GoTo EndLoop
End If
Worksheets("Diagnostics").Visible = True
Worksheets("Diagnostics").Range("C4").CopyFromRecordset ResTemp
z = Sheets("Diagnostics").Range("C4").Value
Sheets("Diagnostics").Visible = False
AftUpD = z
'Debug.Print AftUpD
EndLoop:
ResTemp.Close
dbPP.Close
Set dbPP = Nothing
Set ResTemp = Nothing
'Set SelectionLast = Nothing
'z = Nothing
End Sub
Then I used this value as a variable to make a new SQL query:
Sub Query()
'This query uses the highest ID value in a companion spreadsheet (the public
'variable BfrUpD), which is set in a sub I haven't posted here, to find out
'how many records have been added to the database since the last time the
'spreadsheet was updated, and then copies the new records into the workbook
'Be warned: If you run this query when BfrUpD is equal to or greater than AftUpD it
'will cause a crash. In the end user version of this, I use several If tests,
'comparing BfrUpD with other public variables, to make sure that this doesn't
'happen.
Dim WBout As Excel.Workbook, WSout As Excel.Worksheet
Dim dbPP1 As DAO.Database
Dim qryPP1 As DAO.Recordset
Dim ResTemp1 As DAO.Recordset
Dim TestValue As String
Dim strSQL2 As String
TestValue = BfrUpD
'Debug.Print TestValue
strSQL2 = "SELECT * FROM Table1 WHERE (((Table1.ID)>" & TestValue & "))"
'Debug.Print strSQL2
Set dbPP1 = OpenDatabase("C:\filepath\Database11.mdb")
Set qryPP1 = dbPP1.OpenRecordset(strSQL2)
Set WBout = Workbooks.Open("C:\filepath\h.xlsm")
Set WSout = WBout.Sheets("sheet1")
WSout.Range("A1").End(xlDown).Offset(1, 0).CopyFromRecordset qryPP1
qryPP1.Close
dbPP1.Close
WBout.Save
WBout.Close
MsgBox "Data copied. Thank you."
Set WBout = Nothing
Set WSout = Nothing
Set dbPP1 = Nothing
Set qryPP1 = Nothing
Set ResTemp1 = Nothing
End Sub
EDIT: Code for getting field value directly into variable
Dim dbPP As DAO.Database
Dim ResTemp As DAO.Recordset
Dim z As Long
Dim SelectLast As String
SelectLast = "SELECT Max(Table1.ID) AS MaxOfID FROM Table1"
'Debug.Print SelectLast
Set dbPP = OpenDatabase("C:\filepath\Database11.mdb")
Set ResTemp = dbPP.OpenRecordset(SelectLast)
z = ResTemp(0) 'specifying it's array location (I think) - there is only one
'item in this result, so it will always be (0)
AftUpD = z
'Debug.Print AftUpD
ResTemp.Close
dbPP.Close
Set dbPP = Nothing
Set ResTemp = Nothing
'Set SelectionLast = Nothing
'z = Nothing
End Sub
What you would do is set up and save a query that gets the value for you first. Call it MaxID
e.g
SELECT Max(ID) as result FROM Your_Table_Name
Then, in your VBA code, set your variable to that
eg.
Dim IDresult As Integer
IDresult = DLookup("[result]", "MaxID")
MsgBox(IDresult)
I have a view which is displaying 9 lines of information per every document. In this view I have Export to Excel functionality using the below code to Export document to excel.
Data isn’t exporting properly for first two documents , for example if I have 7 lines for the first document then it should export 7 lines but its exporting 2 lines only . It is happening for the first 2 documents only, from the 3rd document irrespective of any line no.of information it is exporting to excel perfectly. I tried to modify the code for row% from row% = row%+2 to row% = row%+3 , 4 or 5, but its unnecessary creating rows in the excel sheet its not the dynamic one and looks odd as well. Any idea what should I do so that rows should increase dynamically.
Sub Initialize
'On Error Goto errhandler
On Error Resume Next
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doccoll As NotesDocumentCollection
Dim view As NotesView
Dim doc As NotesDocument
Dim otherdoc As NotesDocument
Set db = session.CurrentDatabase
Set view = db.GetView("CRMOpenIssue")
Set doccoll=db.UnprocessedDocuments
Set oExcel = CreateObject ( "Excel.Application" )
Set oWorkbook = oExcel.Workbooks.Add
Set oWorkSheet= oWorkbook.Sheets ( 1 )
oWorkSheet.Cells(1,1).value="Quote# "
oWorkSheet.Cells(1,2).value="Quote Line#"
oWorkSheet.Cells(1,3).value="Customer - fab"
oWorkSheet.Cells(1,4).value="OppNum"
oWorkSheet.Cells(1,5).value="OppLine#"
oWorkSheet.Cells(1,6).value="Open Issue#"
oWorkSheet.Cells(1,7).value="Open Issue"
oWorkSheet.Cells(1,8).value="Category"
oWorkSheet.Cells(1,9).value="Due date"
oWorkSheet.Cells(1,10).value="Owner to resolve issue"
oWorkSheet.Cells(1,11).value="Owner/PME Verify when closed"
oExcel.Worksheets(1).Range("A1:K1").Font.Bold = True
oExcel.columns("A:A").ColumnWidth=15.00
oExcel.columns("B:B").ColumnWidth=8.00
oExcel.columns("C:C").ColumnWidth=15.00
oExcel.columns("D:D").ColumnWidth=10.00
oExcel.columns("E:E").ColumnWidth=8.00
oExcel.columns("F:F").ColumnWidth=8.00
oExcel.columns("G:G").ColumnWidth=30.00
oExcel.columns("H:H").ColumnWidth=30.00
oExcel.columns("I:I").ColumnWidth=15.00
oExcel.columns("J:J").ColumnWidth=15.00
oExcel.columns("K:K").ColumnWidth=30.00
row% = 1
offset% = 0
lastOffset% = 0
If doccoll.count >1 Then 'if more than one doc selected then confirm
resp = Messagebox("Do you want to export only the " & _
"selected " & doccoll.count & " documents?", 36, "Selected only?" )
Else
Messagebox "Exporting all rows. (To export only selected " & _
"rows tick those required in the left margin first.)"
End If '6= yes
oExcel.visible=True
If resp=6 Then 'selected documents
Set doc = doccoll.GetFirstDocument
While Not doc Is Nothing
If resp=6 Then
row% = row%+2
col% = 0 'Reset the Columns
Set otherdoc = view.getnextdocument(doc)
If otherdoc Is Nothing Then
Set otherdoc = view.getprevdocument(doc)
If otherdoc Is Nothing Then
Print " >1 doc should be selected"
End
Else
Set otherdoc = view.getnextdocument(otherdoc)
End If
Else 'got next doc
Set otherdoc = view.getprevdocument(otherdoc)
End If
End If
Forall colval In otherdoc.ColumnValues
col% = col% + 1
If Isarray(colval) Then
columnVal=Fulltrim(colval)
For y = 0 To Ubound(columnVal)
offset% = row% + y +lastOffset%
oWorkSheet.Cells(offset%,col%).value = columnVal(y)
Next
Else
oWorkSheet.Cells(row%, col%).value = colval
End If
End Forall
Set doc = doccoll.GetNextDocument(doc)
Wend
Else 'all documents
Set otherdoc =view.GetFirstDocument
While Not otherdoc Is Nothing
row% = row% + 2
col% = 0 'Reset the Columns
'Loop through all the column entries
'Forall colval In entry.ColumnValues
Forall colval In otherdoc.ColumnValues
col% = col% + 1
If Isarray(colval) Then
columnVal=Fulltrim(colval)
For y = 0 To Ubound(columnVal)
offset% = row% + y +lastOffset%
oWorkSheet.Cells(offset%,col%).value = columnVal(y)
Next
Else
oWorkSheet.Cells(row%, col%).value = colval
End If
End Forall
row%=offset%
Set otherdoc=view.GetNextDocument(otherdoc)
Wend
End If
'errhandler:
Call oExcel.quit()
Set oWorkSheet= Nothing
Set oWorkbook = Nothing
Set oExcel = Nothing
Print "Done"
End Sub
I see you're using Excel automation. Excel automation is cumbersome at times.
I'd try NPOI for Excel XLS files. Take a look at it. Really straightforward to work with:
Create Excel (.XLS and .XLSX) file from C#
There is something very wrong with the code you have uploaded. You must have removed or added an If loop because the first If loop closes before you close the While loop it contains. That being said, this should work, although I haven't tested it.
Option Public
Option Declare
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doccoll As NotesDocumentCollection
Dim view As NotesView
Dim doc As NotesDocument
Dim resp As Integer, row As Integer, offset As Integer, nextrow As Integer, col As Integer
Dim oExcel As Variant
Dim oWorkbook As Variant
Dim oWorkSheet As Variant
On Error GoTo olecleanup
Set db = session.CurrentDatabase
Set view = db.GetView("CRMOpenIssue")
Set doccoll=db.UnprocessedDocuments
Set oExcel = CreateObject ( "Excel.Application" )
Set oWorkbook = oExcel.Workbooks.Add
Set oWorkSheet = oWorkbook.Sheets ( 1 )
oWorkSheet.Cells(1,1).value="Quote# "
oWorkSheet.Cells(1,2).value="Quote Line#"
oWorkSheet.Cells(1,3).value="Customer - fab"
oWorkSheet.Cells(1,4).value="OppNum"
oWorkSheet.Cells(1,5).value="OppLine#"
oWorkSheet.Cells(1,6).value="Open Issue#"
oWorkSheet.Cells(1,7).value="Open Issue"
oWorkSheet.Cells(1,8).value="Category"
oWorkSheet.Cells(1,9).value="Due date"
oWorkSheet.Cells(1,10).value="Owner to resolve issue"
oWorkSheet.Cells(1,11).value="Owner/PME Verify when closed"
oExcel.Worksheets(1).Range("A1:K1").Font.Bold = True
oExcel.columns("A:A").ColumnWidth=15.00
oExcel.columns("B:B").ColumnWidth=8.00
oExcel.columns("C:C").ColumnWidth=15.00
oExcel.columns("D:D").ColumnWidth=10.00
oExcel.columns("E:E").ColumnWidth=8.00
oExcel.columns("F:F").ColumnWidth=8.00
oExcel.columns("G:G").ColumnWidth=30.00
oExcel.columns("H:H").ColumnWidth=30.00
oExcel.columns("I:I").ColumnWidth=15.00
oExcel.columns("J:J").ColumnWidth=15.00
oExcel.columns("K:K").ColumnWidth=30.00
offset% = 0
nextrow% = 3
If doccoll.count >1 Then 'if more than one doc selected then confirm
resp = MessageBox("Do you want to export only the " & _
"selected " & doccoll.count & " documents?", 36, "Selected only?" )
Else
MessageBox "Exporting all rows. (To export only selected " & _
"rows tick those required in the left margin first.)"
End If '6= yes
oExcel.visible=True
If resp=6 Then 'selected documents
Set doc = doccoll.GetFirstDocument
If doccoll.count = 1 Then
Print " >1 doc should be selected"
End If
Else
Set doc =view.GetFirstDocument
End if
While Not doc Is Nothing
row% = nextrow%
col% = 0 'Reset the Columns
nextrow% = row% + 1
ForAll colval In doc.ColumnValues
col% = col% + 1
If IsArray(colval) Then
offset% = row%
ForAll cv In colval
If CStr(cv) <> "" Then
oWorkSheet.Cells(offset%,col%).value = cv
offset% = offset% + 1
End If
End ForAll
If nextrow% < offset% Then nextrow% = offset%
Else
oWorkSheet.Cells(row%, col%).value = colval
End If
End ForAll
If resp=6 Then 'selected documents
Set doc = doccoll.Getnextdocument(doc)
Else
Set doc =view.Getnextdocument(doc)
End If
Wend
oExcel.activeworkbook.close
oExcel.quit
Set oExcel = Nothing
Finish :
Print "Done"
Exit Sub
olecleanup :
' Call LogError() 'Enable to use OpenLog
If Not(IsEmpty(oExcel)) Then
oExcel.activeworkbook.close
oExcel.quit
Set oExcel = Nothing
End If
Resume Finish
End Sub
Uh, this code definitely needs to be more readable, I bet there's a simpler way to do what you want.
OK, can you explain what do you use "CRMOpenIssue" view for?
I suggest you forget about number of lines each document is represented by in your view and use document fields as your data source, instead of data displayed directly in the view columns.