Avoiding The FollowHyperlink Security Warning

This is a brief post about using Application.FollowHyperlink in your databases.

The Problem With FollowHyperlink

I used to use Application.FollowHyperlink because it was so very simple to use to start e-mails, open files, launch a URL, …

Private Sub cmd_StartEmail_Click()
    If IsNull(Me.EmailAddress) = False Then Application.FollowHyperlink Me.EmailAddress
End Sub

until I started getting the dreaded security prompts

Access FollowHyperlink Potential Security Concern

Access FollowHyperlink Error 490

Access FollowHyperlink Debug
Continue reading

Creating Charts In Excel Via Excel Automation In Access

Excel Pie Chart

Today, I thought I talk a little about exporting data from Access to Excel and generate a chart from it.
My hope today is actually 2 fold:

  • Show you how to export data to Excel and generate charts from that data
  • Show you how code can evolve from primitive to reusable user defined procedures (UDP)

Exporting Data To Excel

Built-In Approach With No Control

Most developers know that they can export data to Excel by using the DoCmd.TransferSpreadsheet method

I’m not going to cover this, it is very straightforward and in my opinion a waste as you have no control on formatting, can’t set freeze panes or sorting, can’t automate charts, …

This technique is only good if you only want to get out raw data and don’t care at all about the user experience, say it is being used to feed another system. The minute the Excel file is to be used by mere mortals, using Excel Automation is definitely the way to go, so keep reading.

Using Excel Automation With Full Control

I have already covered the basics of exporting data to Excel in a couple previous posts

So today, I’m assuming that the above is in place and functional. I’m going to instead demonstrate how we can add to the process and create a chart from the data.

Creating an Excel Chart Using VBA Automation

Creating a chart via Excel automation is quite easy, we simply need to use the AddChart2 method

So I exported my data to Excel, started up the Macro Recorder and created a chart. Then reviewed the generated code to give me a starting point. What I got was:

    Range("A1:B6").Select
    ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
    ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$B$6")

And so, I was off to the races!
Continue reading

Working With External Databases in VBA

In my previous post

I demonstrated how you can build queries that directly query with external databases. (queries that query, I know so eloquent of me)

Today however, I thought I’d turn my attention to using VBA to interact with external databases.

VBA Functions

Does a Table Exist

Let’s look at a typical example of checking whether a table exists within a database.

The typical code for working with a local table would be something along the lines of:

Public Function Table_Exist(ByVal sTable As String) As Boolean
    On Error GoTo Error_Handler
    Dim sName                 As String

    sName = CurrentDb.TableDefs(sTable).Name
    Table_Exist = True

Error_Handler_Exit:
    On Error Resume Next
    Exit Function

Error_Handler:
    If Err.Number <> 3265 Then 'Item not found in this collection. / Table doesn't exist
        MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Number & vbCrLf & _
               "Error Source: Table_Exist" & vbCrLf & _
               "Error Description: " & Err.Description & _
               Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
               , vbOKOnly + vbCritical, "An Error has Occured!"
    End If
    Resume Error_Handler_Exit
End Function

And we can use it by simply doing:

Debug.Print Table_Exist("Contacts")

So the question therefore becomes

How can I adapt this code to work with an external database?

Continue reading

VBA – Does A String Contain Special Characters

Trying to help out in an Answers forum question regarding identifying if entries (strings) contained special characters or not

I went digging and updated an existing RegEx function I had from previous work that could do exactly this.

Continue reading

Screenshot/Screen Capture Software Snagit

This is a long overdue post to praise Snagit from TechSmith.

As an Microsoft Access MVP, I have been privileged to get a free NFR license of Snagit.  After many years of use now, I think I owed it to TechSmith to publicly post my praise of their software.

What is Snagit?

For those not already familiar with the product, Snagit is a software that enable you to take a screenshot and then work with it (annotate, save under different formats, and much more).

Snagit lets you quickly capture your screen and camera, add additional context, and share images, GIFs, or videos across your preferred platforms.TechSmith

Continue reading

Pagination on an Access Form

What’s a developer sitting in front of his keyboard going to do with a few free hours? That’s right, have some fun and try and replicate Web Page pagination in his Access form.

In the demo, I have it displaying 10 records per page (as shown in the images above), but you can change that by simply editing the VBA line

Private Const lRecPerPage As Long = 10

and changing the 10 to whatever number of records you wish to display at a time.

There are no ActiveX controls, no APIs, … so this will work in both 32 and 64-bit versions of Access.

Continue reading

Outlook’s Safe Sender Doesn’t Work

This is a continuation on my previous post

Sadly, things appear to be worse than just domain level Safe Senders not being respected.  It would appear the issue affects to specific E-mail addresses as well.

Continue reading

Finding Duplicate Files Using VBA

Today, I thought I’d share a little project I worked on out of personal interest.

Like most people, I have downloaded all sorts of content over the years, backed up pictures and other media and lost control of it all at some point. I wanted to perform a cleanup, but manually figuring this all out is an insurmountable task in many cases. Thus, I set out to see if I could automate the task of identifying duplicates using VBA.

The short answer, is YES, it can be done and this was the result:

Duplicate File Finder

Continue reading

Download a File From The Internet

Today, I thought I’d expand a little on a post I made in 2013:

to adapt the routine to download a copy of the file.  This was actually brought upon by someone needing assistance in Experts-Exchange.

The file in question makes no real difference, images, text files, … So this approach is very versatile and easy to use.
 

Using MSXML2

Based on the original sample, we can read the file using XMLHTTP and then we can simply use ADODB stream to save what we read back to a file.

Continue reading