Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 October 27th, 2008, 10:08 AM
Registered User
 
Join Date: Oct 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access project using event procedures

Hello everybody!

I have a problem with a project.

This project has a form, in which i fill data.

The first Control in the form is a personal ID, with the name "ID Oper B". I want this control to be disabled after I enter data in it.
For that porpuse, i created a OnLostFocus Event, with the Code Builder. The procedure is as follows:

Private Sub ID_Oper_B_LostFocus()
        Me!ID_Oper_B.Enabled = False
End Sub

This procedure does not work: As I fill the data in this control and move focus to the next control, the following message appears:

run time error 2465
Microsoft Office Access can't find the field 'ID_Oper_B' referred to in your expression.

What should I do?

I also want the next Field, named "Operação", to be disabled and locked until it's previous field (ID_Oper_B) has a certain value ("joaquim"). Having that in mind, I created the followin event procedure using the code buider:

Private Sub Operação_BeforeUpdate(Cancel As Integer)
        If Me!ID_Oper_B = "joaquim" Then
        Me!Operação.Enabled = True
        Me!Operação.Locked = False
    Else
        Me!Operação.Enabled = False
        Me!Operação.Locked = True
        End If
End Sub

I also get an error message because of this procedure: exactly the same as above.

What am i doing wrong? Can anybody help me? I would appreciate it!

Thanks

Luís

 
Old October 29th, 2008, 07:33 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

See my other post.

Also, on the first issue, you will need to do this:

Private Sub MyForm_OnCurrent()
If IsNull(Me.ID_Oper_B) Or Me.ID_Oper_B = "" Then
   Me.ID_Oper_B.Enabled = True
Else
   Me.ID_Oper_B.Enabled = False
End If

End Sub

This will keep someone from entering data when they first open the form but the field was filled in previously.

You will also want to put this on the AfterUpdate event for the form.

Is this helping?

mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP ME! Project with event procedures luissilva755 Access VBA 1 October 29th, 2008 07:29 AM
Favorites Project - Right-Click Event Nat4 BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 5 October 24th, 2007 09:49 AM
RecordSets vs Stored Procedures in Access Roy0 SQL Language 0 December 28th, 2005 02:02 PM
Event procedures Primary Form ru1 Access 8 March 7th, 2005 03:58 PM
stored procedures and MS Access madhukp Classic ASP Basics 5 August 26th, 2004 12:22 AM





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