Alex & Access

December 24, 2010

Linked tables – wrong index as primary key

Filed under: Access — access @ 12:19 pm

When Access picks wrong unique index as primary key for linked table – you have to rename Primary key so that it appears first alphabetically.

December 21, 2010

Browse for folder – new folder button

Filed under: Access, VB — access @ 1:48 am

You are normally using SHBrowseForFolder API function to let user browse for folder, sample code you can find at or In order to show "Make new folder" button on this dialog you need to set following flag:

.ulFlags = .ulFlags Or &H40


And MSDN BROWSEINFO Structure page lists other flags you can set for that dialog.

December 12, 2010

DAO RecordsAffected property

Filed under: Access — access @ 7:15 am

RecordsAffected property returns the number of records affected by the most recently invoked Execute method. Can be useful when you need to update a record in a table, and if record not exists – add it. Normally this is solved by opening recordset and using NoMatch property to test if record exists. Using RecordsAffected property you can do this in 3 lines:

Dim dbs As DAO.Database
Set dbs = CurrentDb
dbs.Execute "UPDATE Sales SET Amount=Amount + " & _
varAmount & " Where SalesDate=" & varDate, dbFailOnError
If dbs.RecordsAffected = 0 Then
dbs.Execute "INSERT INTO Sales (Amount, SalesDate) Values(" _ & varAmount & ", " & varDate & ")", dbFailOnError
End If

December 8, 2010

Programmatically create ActiveX control on Access form

Filed under: Access — access @ 8:49 am

To create new control on Access form in design mode you can use CreateControl function, works fine for native controls, but for AcitveX controls (acCustomControl argument) it creates only empty container. Where can you set which control you want to create? The trick is to copy OLEData property from existing control to just created:

Dim frm As Form, ctl As ControlSet
frm = Forms("MyForm") 'Make sure it is opened in design mode
Set ctl = CreateControl(frm.Name, acCustomControl, acDetail, , , 100, 100, 200, 200)
ctl.OleData = frm("cmd001").OleData 'cmd001 already exists on that form, or other opened form
ctl.Name = "cmd002" 

December 1, 2010

Visual Basic for Windows Phone Developer Tools

Filed under: VB, Windows Phone — Tags: , — access @ 11:30 am

Visual Basic for Windows Phone Developer Tools – RTW:  Now we can build applications for Windows Phone 7 using VB.NET. Some sample applications to start with. Time to get new phone…

Create a free website or blog at