Null values for variables in VBA

Dim x As Variant x = Null Only the Variant data type can hold the value Null. A Variant is a special data type that can contain any kind of data […] A Variant can also contain the special values Empty, Error, Nothing, and Null. The “point” of all the other data types is precisely … Read more

UrlDownloadToFile in Access 2010 – Sub or Function not Defined

You’ll need to declare this WinAPI function in order to call it from procedures in your code. From HERE Private Declare Function URLDownloadToFile Lib “urlmon” Alias “URLDownloadToFileA” (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long Public Function DownloadFile(URL As String, LocalFilename … Read more

Create sequential ID value based on the year that a record is added

With Access versions 2010 and later you can use an event-driven data macro to generate the sequential ID. For example, say you have a table named [poledata]. Open it in Design View and add two fields: alternate_id_seq  –  Numeric (Long Integer) alternate_id  –  Text(20) Save the changes to your table and then switch to Datasheet … Read more

ConcatRelated function in a query

Do not call the Module the same as the function, it can sometimes make things confusing for VBA. Rename the module something like “DatabaseUtils” for instance. Make sure the function is really defined as Public Function ConcatRelated(…, the Public here is important, otherwise the function will not be visible outside the module itself.

MS Access prepared statements

Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim strSql As String Set db = CurrentDb strSql = “UPDATE Month_Totals Set item_date = [which_date]” & _ ” WHERE id = [which_id];” Debug.Print strSql Set qdf = db.CreateQueryDef(vbNullString, strSql) With qdf .Parameters(“which_date”).Value = Date() .Parameters(“which_id”).Value = 1 .Execute dbFailOnError End With That example used a new, … Read more