Error Running MS Access Macro from Task Scheduler

Question and solution here: https://superuser.com/questions/402070/run-task-scheduler-task-on-demand-from-limited-user-account-in-windows-7

Go to C:\Windows\System32\Tasks find the related task and assign "read and execute" rights to the user you want to be able to access it. Be sure to assign to "current object only." Then the task will be visible and runnable from the limited user, and it will work if you saved your credentials in it and checked "run whether user is logged on or not."

VBA win-7 64 bit error (run-time error 429 activex component can't create object)

You created a DLL in Visual Studio 2010 so you can reference it in MS Access VBA.

It works fine in 32-bit Office but you get an error (error 429 activex component can't create object) when trying to run in 64-bit Office.

Solution: Unfortunatley non built-in ActiveX objects cannot be created in 64-bit Office and there is no direct work around for this.

VBA Compile Error: Procedure Too Long

I ran into a very strange error recently when I took over someone elses MS Access project. The so called developer did not use Option Explicit anywhere in the code so I added it into all modules and fixed all the misspelled variables and missing variables. Then the final Error I got when compiling was "Procedure Too Long"! That was odd as the routine in question was maybe 1000 lines long so it was NOT too long at all. After reviewing the code in more detail I decided to change some of the massive If-Then-Else blocks into Case Statements and just like magic, after the first one, I was able to get past this stupid error.

There must be some sort of limitation on the number of If-Else statements in VBA routines.

SQL Server "Optional Feature Not Implemented" Error Message

From here: https://support.microsoft.com/en-ca/help/214459/info-optional-feature-not-implemented-error-message

I got this error when running the code via MS Access VBA.

When you use ActiveX Data Objects (ADO) to pass parameters to a stored procedure, you may receive the following error:

Run-time error '2147217887 (80040e21)':
[Microsoft][ODBC SQL Server Driver] Optional Feature Not Implemented.

This error can occur if you attempt to set the TYPE of a parameter in an ADODB command object's parameters collection to a type that is not supported by the data provider.

For example, using SQL Server 7.0, create a stored procedure on the PUBS database:

   CREATE PROCEDURE GetEmployeeInfo (@thedate datetime, @NumEmployees int output)AS 
SELECT @NumEmployees = count(*) FROM EMPLOYEE WHERE hire_date < @thedate
GO

This stored procedure returns an output parameter of type int indicating the number of employees hired before a given date. The date is passed to the stored procedure as a parameter, and the number of employees is passed to the calling program as an output parameter.

Now create an ADO application to use the stored procedure. The example given is written in Visual Basic.

Private Sub MySubroutine()
Dim dbConnection As ADODB.Connection
Dim dbCommand As ADODB.Command

Set dbConnection = New ADODB.Connection
Set dbCommand = New ADODB.Command

Dim DSNNAME As String
Dim USERNAME As String
Dim PASSWORD As String

DSNNAME = "Pubs"
USERNAME = "sa"
PASSWORD = ""

dbConnection.Open DSNNAME, USERNAME, PASSWORD
dbCommand.ActiveConnection = dbConnection

Dim TheDate As Date
TheDate = Now

dbCommand.CommandText = "GetEmployeeInfo"
dbCommand.CommandType = adCmdStoredProc
dbCommand.Parameters.Append dbCommand.CreateParameter("@thedate", adDBDate, adParamInput, 0, TheDate)
dbCommand.Parameters.Append dbCommand.CreateParameter("@NumEmployees", adInteger, adParamOutput, 0)
dbCommand.Execute

Dim strTheString As String
strTheString = "There are " & dbCommand.Parameters("@numemployees") & " employees who were hired before " & TheDate
MsgBox strTheString, vbOKOnly, "Demonstration"
End Sub

When the sample code is run, it gives this error:

Run-time error '2147217887 (80040e21)':
[Microsoft][ODBC SQL Server Driver] Optional feature not Implemented.

This is because SQL Server does not support the adDBDate datatype. To correct this problem, change the datatype of the @theDate parameter to adDBTimeStamp.

In order to determine the number, names, types, and sizes of parameters needed in a stored procedure, use the Parameters.Refresh method of the command object. You can call this method during development of your application to determine the correct requirements for the stored procedure, then remove the expensive call to Parameters.Refresh after you have gathered the necessary data.

MS Access VBA for NumLock Control

Option Compare Database
Option Explicit

Private Declare PtrSafe Sub keybd_event Lib "user32" ( _
    ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, _
    ByVal dwExtraInfo As Long)
    Private Const VK_NUMLOCK = &H90
    Private Const KEYEVENTF_KEYUP = &H2
    Declare Function GetKeyState Lib "user32.dll" ( _
    ByVal nVirtKey As Long) As Integer
 
Public Sub NUM_TOGGLE()
    keybd_event VK_NUMLOCK, 1, 0, 0
    keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End Sub
 
Public Sub NUM_On()
    If Not (GetKeyState(vbKeyNumlock) = 1) Then
        keybd_event VK_NUMLOCK, 1, 0, 0
        keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
    End If
End Sub
 
Public Sub NUM_Off()
    If (GetKeyState(vbKeyNumlock) = 1) Then
        keybd_event VK_NUMLOCK, 1, 0, 0
        keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
    End If
End Sub

Using FindFirst in Access VBA with GUID

Private Sub cmdRefreshAllRecords_Click()
    Dim strGuidID As String
    Dim rst As DAO.Recordset
       
    ' This is NOT how to get the GUID
    ' The result will be "????????"
    strGuidID = Me.ID
   
    ' This will get the GUID. StringFromGUID is a built in MS Access function
    strGuidID = StringFromGUID(Me.ID)
   
    ' You can also get the GUID from the actual Records Field
    strGuidID = Me.Recordset.Fields("ID")
   
    Me.Requery
   
    Set rst = Me.RecordsetClone
   
    If rst.RecordCount > 0 Then
        ' Here we must convert the ID field using the StringFromGUID field.
        ' ID is the name of the field in the Recordset/Underlaying Form
        rst.FindFirst "StringFromGUID(ID) = " & strGuidID
        Me.Bookmark = rst.Bookmark
    End If
   
    Set rst = Nothing
   
End Sub

FileSystemObject Run-Time error 13 Type Mismatch

You get a Type Mismatch Error on the GetFolder line!! Why is that? Because the Folder declaration needs to be like this: Dim oFolder As Scripting.Folder. This will be the case even if you have a reference to Microsoft Scripting Runtime.

The code below will fail. Add the Scripting. to the Folder declarion and it will work!

Dim oFileSystem As New FileSystemObject
Dim oFolder As Folder
Dim oCurrentFile As File
Dim oFileColl As Files

Set oFolder = oFileSystem.GetFolder("d:\data\bradfb\Desktop\CR Disposition\")
Set oFileColl = oFolder.Files

If oFileColl.Count > 0 Then
    With lstFiles
        For Each oCurrentFile In oFileColl        
            .AddItem oCurrentFile.Name            
        Next        
        .ListIndex = 0        
    End With
   
End If

Set oFileSystem = Nothing
Set oFolder = Nothing
Set oFileColl = Nothing