Skip to Content
VB & VBA in a Nutshell: The Language
book

VB & VBA in a Nutshell: The Language

by Paul Lomax
October 1998
Intermediate to advanced
656 pages
16h 10m
English
O'Reilly Media, Inc.
Content preview from VB & VBA in a Nutshell: The Language
Err.LastDLLError Property

Syntax

Err.LastDLLError

Description

A read-only property containing a long data type representing a system error produced within a DLL called from within a VB program.

Rules at a Glance

  • Only direct calls to a Windows system DLL from VB code assign a value to LastDLLError.

  • The value of the LastDLLError property depends upon the particular DLL being called. Your code must be able to handle the various codes that can be returned by the DLL you are calling.

  • Don't forget that a failed DLL call doesn't itself raise an error within your VB program. As a result, the Err object's Number, Description, and Source properties aren't filled.

Programming Tips and Gotchas

  • The LastDLLError property is used only by system DLLs, such as kernel32.dll, and therefore errors that occur within DLLs you may have created in VB won't be assigned.

  • Obtaining accurate documentation about the return values of system DLLs can be a challenging experience. Most useful information can be found by studying the API documentation for Visual C++. However, you can use the Windows API FormatMessage to return the actual Windows error message string from within Kernel32.DLL, which incidentally is also in the correct language. The following is a brief example you can use in your applications to display the actual Windows error description:

    Option Explicit Declare Function FormatMessage Lib "kernel32" _ Alias "FormatMessageA" _ (ByVal dwFlags As Long, lpSource As Any, _ ByVal dwMessageId As Long, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Programming Excel with VBA and .NET

Programming Excel with VBA and .NET

Jeff Webb, Steve Saunders

Publisher Resources

ISBN: 1565923588Catalog PageErrata