473,513 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hyperlinks.Add from Access to Excel

4 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim dteStartDate as Date
  3. Dim dteEndDate as Date
  4. Dim rstSummary As DAO.Recordset
  5. Dim objApp As Object
  6. Dim objBook As Object
  7. Dim objSheet As Object
  8. Dim x As Integer
  9. Dim strSheet as String
  10.  
  11. dteStartDate = Me.txtReportStartDate
  12. dteEndDate = Me.txtReportEndDate
  13.  
  14. Set objApp = CreateObject("Excel.Application")
  15. Set objBook = objApp.Workbooks.Add(1)
  16. Set objSheet = objBook.Worksheets("Sheet1")
  17. objApp.Visible = True
  18. objApp.ActiveWindow.WindowState = xlMaximized
  19. i = 1
  20. With objSheet
  21.     .Name = DLookup("EmployeeLastName", "tblEmployeeMaster", "[EmployeeMasterID]=" & varItem) & "_RepQueue_Summary"
  22.     .Range("A1") = "xxx"
  23.     .Range("A2") = "xxx"
  24.     .Range("A3") = "Manager: xxx"
  25.     .Range("A4") = "Representative Workqueues Tracking Summary " & Format(dteStartDate, "mmmm d, yyyy") & " and " & Format(dteEndDate, "mmmm d, yyyy")
  26.     .Range("A1:A4").Font.Bold = True
  27.     strSQL = ""
  28.     strSQL = strSQL & " TRANSFORM Sum(StatusBalance) AS SumOfEncounters"
  29.     strSQL = strSQL & " SELECT Representative, EmployeeResponsibility  AS [Responsibility], Sum(Encounters) AS [Avg]"
  30.     strSQL = strSQL & " FROM tblWeeklyQueueSummary_Temp"
  31.     strSQL = strSQL & " GROUP BY Representative, EmployeeResponsibility,"
  32.     strSQL = strSQL & " EmployeeLastName, EmployeeFirstName"
  33.     strSQL = strSQL & " ORDER BY EmployeeResponsibility, EmployeeLastName, EmployeeFirstName"
  34.     strSQL = strSQL & " PIVOT Format(DateValue([SummaryStatusDate]), 'd-mmm')"
  35.     Set rstSummary = CurrentDb.OpenRecordset(strSQL, dbReadOnly)
  36.         For x = 1 To rstSummary.Fields.Count
  37.             .Cells(6, x) = rstSummary(x - 1).Name
  38.         Next x
  39.         y = 7
  40.         Do Until rstSummary.EOF
  41.             For x = 1 To rstSummary.Fields.Count
  42.                 If x = 1 Then
  43.                     strSheet = ""
  44.                     strSheet = Trim(Left(rstSummary(0), InStr(rstSummary(0), ",") - 1)) & "_"
  45.                     strSheet = strSheet & Mid(rstSummary(0), InStr(rstSummary(0), ",") + 2, 1) & "_"
  46.                     strSheet = strSheet & "WorkQueue_Summary"
  47.                     Debug.Print strSheet
  48.                     .Hyperlinks.Add Anchor:=.Range("A" & y), Address:="", _
  49.                     SubAddress:=Chr(39) & strSheet & Chr(39) & "!A1", _
  50.                     TextToDisplay:=rstSummary(0)
  51.                 Else
  52.                     .Cells(y, x) = rstSummary(x - 1)
  53.                 End If
  54.             Next x
  55.             .Cells(y, 3).FormulaR1C1 = "=AVERAGE(RC[1]:RC[" & x - 2 & "])"
  56.             y = y + 2
  57.             rstSummary.MoveNext
  58.         Loop
  59. End with
I get run time error 5 on the Hyperlinks.Add method

Thanks for looking.
Apr 30 '20 #1
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.
Apr 30 '20 #2
dashiellx
4 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. 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.
Apr 30 '20 #3
dashiellx
4 New Member
Figured it out:

Expand|Select|Wrap|Line Numbers
  1. .Range("A" & y).Select
  2. ActiveCell.Hyperlinks.Add .Range("a" & y), "", Chr(39) & strSheet & Chr(39) & "!A1", , CStr(rstSummary(0))
  3.  
Apr 30 '20 #4
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 :
Expand|Select|Wrap|Line Numbers
  1. .Hyperlinks.Add Anchor:=.Range("A" & y), _ 
  2.                 Address:="", _
  3.                 SubAddress:=Chr(39) & strSheet & Chr(39) & "!A1", _
  4.                 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 :-)
Apr 30 '20 #5
dashiellx
4 New Member
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.
Apr 30 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2923
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...
2
2372
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;";...
1
11615
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...
3
2943
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...
3
10702
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...
1
2790
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...
4
7114
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...
4
2747
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...
4
15378
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...
0
1528
by: Nadirsha Muhammed | last post by:
How to access excel function wizard through C#
0
7260
marktang
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,...
0
7161
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...
0
7539
jinu1996
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...
1
7101
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...
0
7525
tracyyun
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...
0
5686
agi2029
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,...
1
5089
isladogs
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...
0
4746
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...
0
3234
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.