You are here Microsoft Access

Welcome to the Creative Connections Microsoft Access blog

Having been asked by two clients recently if we could design and build them bespoke MS Access databases, we thought now would be a good time to start a blog sharing all the nifty tips and tricks that we have employed, using built in MS Access functions, Macro Tools and VBA.

 

The databases that we recently built were for an Electric Bike Retailer and a Roller Skating and Events Venue in Southampton and included the following main capabilities:

  • Customer data capture 
  • Customer contact management
  • Sales & events quotations
  • Sales order processing and invoicing
  • Stock control
  • Customer data extraction for marketing (producing mailing lists and email list for use with email marketing tools like MailChimp etc...) Bike service history
  • One click emailing from individual customer records (allowing both custom and standard emails to be sent)

How To Update A Record In A Microsoft Access Table Using VBA

HOW TO UPDATE A RECORD IN A MICROSOFT ACCESS TABLE USING VBA / UPDATING A RECORD IN AN ACCESS TABLE BASED ON USER INPUT

APPLIES TO:  ACCESS 2007, 2010 (UNTESTED IN EARLIER VERSIONS)

The following tutorial will show you how to update a record in an MS Access table when a user clicks a button using VBA and SQL.

For this tutorial you will need to create the following:

  • A table called “tblAccessories”, with the following fields:
    • A field called “accessoryId” (the field data type should be number)
    • A field called “accessoryName” (the field data type should be text)
  • A record in tblAccessories with the field “accessoryId” set as 1

Note: Data types are very important when performing this type of operation so always ensure that you are working with the correct data type that you are trying to update.

  • A form called “frmAddAccessory”
  • A field on the form called “textbox1”
  • A command button on the form called “btnAdd”

This example will demonstrate how to update a record in a table based on user input in an access text box on a form.

1. On the form you have created as per the above instructions, select the command button called “btnAdd”

2. In the tools section of the “Design” tab click on the item called “Property Sheet” and select the “Event ” tab

3. On the “On Click” property click on the little black down arrow / triangle and select “Event Procedure”

4. Click on the three dots next to the little black down arrow / triangle - this will open up the VBA window and you should see the following:

Private Sub btnAdd_Click()

End Sub

5. On a new line directly between the two lines above add the following 

DoCmd.RunSQL "Update tblAccessories SET accessoryName = " & Me!textBox1 & "  WHERE accessoryId = 1"

Save your changes and test your form / report

Print An MS Access Report To A Specific Network Printer

Applies to:  Access 2007, 2010 (untested in earlier versions)

Having recently had a problem with a clients MS Access 2007 database where they wanted to print labels to a specific networked printer, I discovered that there was a recognised bug in MS Access 2007 that stops you being able to do this using the option to set the the printer in the reports design view. (It allows you to select the printer, but when you close and save the report it goes back to the default printer).

To get round this problem, I came up with three solutions:

  1. Upgrade to Access 2010 (not pratical for this clients existing database)
  2. Use Microsoft Hotfix ( read supporting text thoroughly before applying)
  3. Hardcode your printer selection using VBA (link to excellent VBA code example)

I went for option three, the code is very well written with excellent comments and I only had to change the printer name and report name.

Page 1 of 7

  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  5 
  •  6 
  •  7 
  •  Next 
  •  End 
  • »