Wrox Programmer Forums
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 7th, 2005, 10:31 AM
Authorized User
Join Date: Apr 2005
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Form Event Procedure Help

Hello all,

I have asked questions in this forum previously and have received helpful information. Thank you.:) I am still an infant programmer and I appreciate all the help I receive. So here is my next question.

I am using a command button, “Edit Contact Information”, to close the form “frmInventoryTracking” and opening the form “frmCustomerContactEdit”. The command button is intended to close "frmInventoryTracking", open "frmCustomerContactEdit" and go directly to the selected “CustomerID” (the CustomerID was entered in the "CustomerID" Combobox in "frmInventoryTracking" before clicking "Edit Contact Information"). Form "frmCustomerContactEdit" is bound to the table "tblCustomers". The information that is being edited is "ContactName" and "FaxNumber".

The command button works correctly if there is data in the CustomerID ComboBox. However, if there is not any data in the CustomerID ComboBox, I receive the following syntax error “Syntax Error (missing operator) in query expression ‘[CustomerID]=’. When I click OK, form “frmInventoryTracking” still closes and the entire database disappears.

I would like to press OK and put another error message box “Must select Customer” on the screen, click OK and then return to “frmInventoryTracking”.

Here is the code I have written.

Private Sub Edit_Contact_Information_Click()
On Error GoTo Err_CustomerContactEdit_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmCustomerContactEdit"

    stLinkCriteria = "[CustomerID]=" & Me![CustomerID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit Sub

    MsgBox Err.Description
    Resume Exit_CustomerContactEdit_Click:

End Sub

Any help will again be appreciated.

D. Bartelt
D. Bartelt
Old June 7th, 2005, 12:10 PM
Friend of Wrox
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts

You must test null value before assigning a value to stLinkCriteria variable

If IsNull(Me![CustomerID]) Then
    MsgBox "You Must select a Customer"
    Exit Sub
    'Code here to continue
End If

Old June 7th, 2005, 04:10 PM
Authorized User
Join Date: Apr 2005
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts

Thank you.

It works. I appreciate your help.

D. Bartelt

Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Procedure malfunction - duplicating records dstein4d Access VBA 0 April 4th, 2008 03:02 PM
Choosing the correct Event Procedure ru1 Access 3 October 31st, 2006 04:30 PM
Event Procedure help dbartelt Access VBA 3 May 20th, 2005 05:36 PM
Event Procedure help dbartelt Access 2 May 19th, 2005 03:35 AM
How to use KeyDown event in Form zhangxujun1981 C# 5 July 6th, 2004 02:07 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.