Trouble with InputBoxes

Here is a way to catch most outcomes of interacting with the dialog; Dim value As String value = InputBox(“Please enter a #”, “Determine Limit”, 10000) If (StrPtr(value) = 0) Then MsgBox “You pressed cancel or [X]” ElseIf (value = “”) Then MsgBox “You did not enter anything” ElseIf (Val(value) = 0 And value <> … Read more

Check if access table exists

You can use the hidden system table MSysObjects to check if a table exists: If Not IsNull(DlookUp(“Name”,”MSysObjects”,”Name=”TableName””)) Then ‘Table Exists However, I agree that it is a very bad idea to create a new table every day. EDIT: I should add that tables have a type 1, 4 or 6 and it is possible for … Read more

How to refer to Excel objects in Access VBA?

I dissent from both the answers. Don’t create a reference at all, but use late binding: Dim objExcelApp As Object Dim wb As Object Sub Initialize() Set objExcelApp = CreateObject(“Excel.Application”) End Sub Sub ProcessDataWorkbook() Set wb = objExcelApp.Workbooks.Open(“path to my workbook”) Dim ws As Object Set ws = wb.Sheets(1) ws.Cells(1, 1).Value = “Hello” ws.Cells(1, 2).Value … Read more

Different LIKE behaviour between my application and the Access query wizard

You are getting tripped up by the difference in LIKE wildcard characters between queries run in Access itself and queries run from an external application. When running a query from within Access itself you need to use the asterisk as the wildcard character: LIKE ‘*Ra*’. When running a query from an external application (like your … Read more

How to loop through all controls in a form, including controls in a subform – Access 2007

You can use recursion Public Sub colCtrlReq(frm As Form) ” Sets background color for required field -> Tag = * Dim setColour As String setColour = RGB(255, 244, 164) Dim ctl As Control For Each ctl In frm If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox _ Or ctl.ControlType = acListBox Then If InStr(1, ctl.Tag, … Read more

Save password for ODBC connection to MS SQL server from MS Access 2007

The best solution is obviously to use Windows security. If that is not suitable, here is a possible alternative trick, exploiting the fact that Access remembers all opened connections until the program is closed: copy the connect string of one of your tables create a passthru queries “ptqConnect” and enter any fast SQL statement in … Read more