Long story short, due to some very specific formatting requirements, I can't just export the data to excel and create a pivot table.
So, I need to create a tab for each category and on the first "summary" sheet have the value in Column A (the category) be a hyperlink that opens goes to Range "A1" on the detail sheet.
For each category, there is a detail sheet with the name of the Workflow State (space removed) followed by "_Detail". All of the categories are at least two rows, but they can be up to 5.
Here is the code I have so far: - Dim strSQL As String
-
Dim dteStartDate as Date
-
Dim dteEndDate as Date
-
Dim rstSummary As DAO.Recordset
-
Dim objApp As Object
-
Dim objBook As Object
-
Dim objSheet As Object
-
Dim x As Integer
-
Dim strSheet as String
-
-
dteStartDate = Me.txtReportStartDate
-
dteEndDate = Me.txtReportEndDate
-
-
Set objApp = CreateObject("Excel.Application")
-
Set objBook = objApp.Workbooks.Add(1)
-
Set objSheet = objBook.Worksheets("Sheet1")
-
objApp.Visible = True
-
objApp.ActiveWindow.WindowState = xlMaximized
-
i = 1
-
With objSheet
-
.Name = DLookup("EmployeeLastName", "tblEmployeeMaster", "[EmployeeMasterID]=" & varItem) & "_RepQueue_Summary"
-
.Range("A1") = "xxx"
-
.Range("A2") = "xxx"
-
.Range("A3") = "Manager: xxx"
-
.Range("A4") = "Representative Workqueues Tracking Summary " & Format(dteStartDate, "mmmm d, yyyy") & " and " & Format(dteEndDate, "mmmm d, yyyy")
-
.Range("A1:A4").Font.Bold = True
-
strSQL = ""
-
strSQL = strSQL & " TRANSFORM Sum(StatusBalance) AS SumOfEncounters"
-
strSQL = strSQL & " SELECT Representative, EmployeeResponsibility AS [Responsibility], Sum(Encounters) AS [Avg]"
-
strSQL = strSQL & " FROM tblWeeklyQueueSummary_Temp"
-
strSQL = strSQL & " GROUP BY Representative, EmployeeResponsibility,"
-
strSQL = strSQL & " EmployeeLastName, EmployeeFirstName"
-
strSQL = strSQL & " ORDER BY EmployeeResponsibility, EmployeeLastName, EmployeeFirstName"
-
strSQL = strSQL & " PIVOT Format(DateValue([SummaryStatusDate]), 'd-mmm')"
-
Set rstSummary = CurrentDb.OpenRecordset(strSQL, dbReadOnly)
-
For x = 1 To rstSummary.Fields.Count
-
.Cells(6, x) = rstSummary(x - 1).Name
-
Next x
-
y = 7
-
Do Until rstSummary.EOF
-
For x = 1 To rstSummary.Fields.Count
-
If x = 1 Then
-
strSheet = ""
-
strSheet = Trim(Left(rstSummary(0), InStr(rstSummary(0), ",") - 1)) & "_"
-
strSheet = strSheet & Mid(rstSummary(0), InStr(rstSummary(0), ",") + 2, 1) & "_"
-
strSheet = strSheet & "WorkQueue_Summary"
-
Debug.Print strSheet
-
.Hyperlinks.Add Anchor:=.Range("A" & y), Address:="", _
-
SubAddress:=Chr(39) & strSheet & Chr(39) & "!A1", _
-
TextToDisplay:=rstSummary(0)
-
Else
-
.Cells(y, x) = rstSummary(x - 1)
-
End If
-
Next x
-
.Cells(y, 3).FormulaR1C1 = "=AVERAGE(RC[1]:RC[" & x - 2 & "])"
-
y = y + 2
-
rstSummary.MoveNext
-
Loop
-
End with
I get run time error 5 on the Hyperlinks.Add method
Thanks for looking.
5 1488 NeoPa 32,557
Recognized Expert Moderator MVP
Hi. Welcome to Bytes.com.
There's a lot of good & tidy information in your question that makes most of it easy to follow. There's also some information missing that is quite hard to work without. An error message is always required. Error numbers are unhelpful on their own.
In this case, from what I can see, I would guess that hyperlinks don't like an empty or invalid address. How it determines what is valid I don't know but I would guess empty (ZLS) would be recognised as invalid quite simply.
I suspect you want to fill that data in later but you may need to create it with some sort of valid - or valid looking - value in order to get further.
All in all a pretty tidy question for a first time but there are a couple of variables that are referred to without any declarations and, as I say, the error message is always required when there is one.
Whoops, Run-Time Error '5' is Invalid Procedure Call or Argument. And yep, I did forgot to copy the Dim i/y = integer declarations when getting on the site. Sorry. :)
I don't believe it is the zero length string. As this works in excel: - ActiveSheet.Hyperlinks.Add Anchor:=ActiveSheet.Range("C1"), Address:="", SubAddress:="'Test'!A1", TextToDisplay:= "Test"
And the sheet Test doesn't exist in the workbook either.
Thanks for looking.
Figured it out: -
.Range("A" & y).Select
-
ActiveCell.Hyperlinks.Add .Range("a" & y), "", Chr(39) & strSheet & Chr(39) & "!A1", , CStr(rstSummary(0))
-
NeoPa 32,557
Recognized Expert Moderator MVP
Ah. I didn't recognise the first time that you were using line continuations. With indented code I find it helps to indent such to make it clear : - .Hyperlinks.Add Anchor:=.Range("A" & y), _
-
Address:="", _
-
SubAddress:=Chr(39) & strSheet & Chr(39) & "!A1", _
-
TextToDisplay:=rstSummary(0)
I must admit I see nothing obviously wrong with your code. Perhaps you could use Debug.Print to show the values of all your parameters at the time of invoking and post them into the thread.
Another thing that might be helpful is to confirm that the code has been compiled before you run it.
Good work so far though. You're an easy person to work with :-)
I'm sure some of my coworkers would dispute the ease of working with me, but I take it. :-)
I was able to figure this out and I posted some working code above.
Thanks again for looking.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: ImraneA |
last post by:
Hi there
Have a database, where front-end interface allows user to select a ms
access database. From there, standard tables are linked. Routine,
that creates a spreadsheet, for each table a...
|
by: Acephalus |
last post by:
I am currently using this to get data from an .xls
file:string conn =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + file + ";" +
"Extended Properties=Excel 8.0;";...
|
by: tkaleb |
last post by:
I have to create output file in a text, MS Access, MS Excel and .dbf format
from C# Win/ADO.NET application. Data are collected in DataSet and there is
no problem to make text file. However, I have...
|
by: Omar |
last post by:
Hi Developers,
I am trying to access an Excel data file through a VB.Net application.
I have the following code:
=================================== VB.Net Code ===================
Dim...
|
by: James Wong |
last post by:
Dear all,
I have an old VB6 application which can create and access Excel object. The
basic definition statements are as follows:
Dim appExcel As Object
Dim wkb1 As Excel.Workbook
Dim wks1...
| |
by: Sean Howard |
last post by:
I have an Access database/procedure that exports data to an Excel
spreadsheet and opens that spreadsheet using automation
I need to change the current directory/drive in Excel to be the same as...
|
by: Janelle.Dunlap |
last post by:
When I import an Excel file containing hyperlinks into Access, the
hyperlinks turn into text and no longer hold their links. I am using
the TransferSpreadsheet function in Access to import my...
|
by: Keith Wilby |
last post by:
How controllable from Access VBA is Excel? I'm currently using automation
to dump 2 columns of data into an Excel spreadsheet so that the end user can
create a line graph based on it. Could the...
|
by: christianlott1 |
last post by:
I've linked an excel worksheet as an access table. The values appear
but it won't allow me to change any of the values.
To test I've provided a fresh blank workbook and same problem.
I've done...
|
by: Nadirsha Muhammed |
last post by:
How to access excel function wizard through C#
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |