Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Using If ElseIf to Evaluate
Don Gregory 
      
9 months ago
I am totally stumped on this. I have a table into which a user can import data from a spreadsheet. Once the data is imported into the table, I want to ensure that the data is cleaned up for consistency. Here is the VBA code:
If Forms![frm_tbl_EFT_Temp]![Source] = "PAYPAL" Then
        Forms![frm_tbl_EFT_Temp]![Source] = "Paypal"
ElseIf Forms![frm_tbl_EFT_Temp]![Source] = "paypal" Then
        Forms![frm_tbl_EFT_Temp]![Source] = "Paypal"
ElseIf Forms![frm_tbl_EFT_Temp]![Source] = "nfg" Then
        Forms![frm_tbl_EFT_Temp]![Source] = "NFG"
ElseIf Forms![frm_tbl_EFT_Temp]![Source] = "Nfg" Then
        Forms![frm_tbl_EFT_Temp]![Source] = "NFG"
ElseIf Forms![frm_tbl_EFT_Temp]![Source] = "BEVITY" Then
        Forms![frm_tbl_EFT_Temp]![Source] = "Bevity"
ElseIf Forms![frm_tbl_EFT_Temp]![Source] = "bevity" Then
        Forms![frm_tbl_EFT_Temp]![Source] = "Bevity"
End If
What's happening is that only one set of data is cleaned up on the form. "Paypal" is cleaned up, but "Nfg" is not cleaned up.
I have done numerous internet searches and I even tried to use Case to get this to work. Nothing seems to fix the problem.
Do you have any suggestions as to what I am doing wrong?
Adam Schwanz  @Reply  
           
9 months ago
You are only editing one record at a time with that setup. What you need is a recordset to go over all the records. Or you can use update queries.

I don't think this is case sensitive either like some other languages. This below should update all your stuff regardless of the capitalization. (Make a backup before you try as it is updating many records)

CurrentDb.Execute "Update TableName Set Source='Paypal' Where Source='paypal'"
CurrentDb.Execute "Update TableName Set Source='NFG' Where Source='nfg'"
CurrentDb.Execute "Update TableName Set Source='Bevity' Where Source='bevity'"

Kevin Yip  @Reply  
     
9 months ago
@0[Don-Gregory] If you have "Option Compare Database" at the top of your VBA module (as is usually the case), then string comparisons are not case-sensitive -- "PAYPAL" will always equal "Paypal" or "paypal".  You can use update queries as Alex suggested.  If you must use VBA, then you can take advantage of the case-insensitive nature of the comparisons to simplify your code to something like:

Dim s As String
s = Forms![frm_tbl_EFT_Temp]![Source] & ""
If s = "paypal" Then s = "Paypal"
If s = "nfg" Then s = "NFG"
If s = "bevity" Then s = "Bevity"
Forms![frm_tbl_EFT_Temp]![Source] = s

No need to use ElseIf to check the various cases of the string.
John Williams  @Reply  
     
9 months ago
Why not simply go upper case for all s=ucase(s)  which will convert all entries to uppercase?  Then you would not the need for the giant IF/Then.
Don Gregory OP  @Reply  
      
9 months ago
I ended up just creating 3 data queries, much like what Greg proposed. This worked great and avoided that hideous If ElseIf.
I went down this road mainly to try to accommodate the users and what they expect to see. I also wanted the data to be consistent. Thank you all for taking the time to reply.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/30/2026 1:39:23 AM. PLT: 1s