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 August 12th, 2009, 05:00 AM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Setting a form's field with VBA!

Hello everybody!
this is my first participation in this forum!
Si I have to create a form, I have a field "note_quality" & another field including in the form "Texte7", I want to create a VBA code which do :
If note_quality=1 or 2 then Texte7=Bad quality
If note_quality=3 then Texte7=medium quality
If note_quality=4 then Texte7=Good quality
If note_quality=5 then Texte7=great quality

Also Texte7 is not a table's field, it's just created in the form.

Thanks!
 
Old August 13th, 2009, 08:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Welcome to Wrox!

Your logic can be solved using the CASE syntax.

Code:
Select Case Me.note_quality
    Case 1, 2
        Me.Texte7 = "Bad Quality"
    Case 3
        Me.Texte7 = "Medium Quality"
    Case 4
        Me.Texte7 = "Good Quality"
    Case 5
        Me.Texte7 = "Great Quality"
End Select
There's even a CASE ELSE you can use where you catch everything else that's not between 1 and 5.
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
 
Old August 16th, 2009, 08:03 AM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot bro!
But I still have problem, I wrote this code in Access by cearting a VBA evenemential code, it doesn't work, I activated macros but it doesn't work
 
Old August 17th, 2009, 04:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

I don't know what you mean by "VBA evenemential code." Please explain.
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
 
Old August 18th, 2009, 12:07 PM
Registered User
 
Join Date: Aug 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In Access, I created a VBA code in the form, I clicked (right) in the controle & I chose "Create a code" & after, "VBA code" & I wrote the code & I saved it!
 
Old August 18th, 2009, 12:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Sorry, but I'm still not understanding what that means in reference to the code example that I wrote.
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
 
Old September 18th, 2009, 09:26 AM
JP JP is offline
Authorized User
 
Join Date: Apr 2008
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I think he means he needs the proper event to put the procedure. The AfterUpdate event would probably be the most appropriate.

Code:
Private Sub note_quality_AfterUpdate()
Select Case Me.note_quality
    Case 1, 2
        Me.Texte7 = "Bad Quality"
    Case 3
        Me.Texte7 = "Medium Quality"
    Case 4
        Me.Texte7 = "Good Quality"
    Case 5
        Me.Texte7 = "Great Quality"
End Select 
 
End Sub
--JP

Quote:
Originally Posted by SerranoG View Post
Sorry, but I'm still not understanding what that means in reference to the code example that I wrote.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Form's calculated field not working properly PaulJH Access 11 March 5th, 2007 09:52 AM
Form's Unbound field question ebburks Access 4 June 6th, 2006 07:37 AM
Setting visible property on a report field tnzabo Access 3 July 21st, 2005 11:30 AM
Word VBA - Text Form Field dkr72 Excel VBA 1 December 22nd, 2004 11:09 AM





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