Results 1 to 2 of 2
  1. #1
    RussH is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    6

    Case Statement

    Can you loop through Case Statements?



    Currently I have a table with information in field 1 that I need to change and drop into field 2. I created a form with these 2 fields and with VBA code on the onload event and tried oncurrent event. The code is like this:

    Select Case [ResultsCourse]
    Case [ResultsCourse] = "12 month competency"
    ULTICOUCODES = "12MO"
    Case [ResultsCourse] = "18 month competency"
    ULTICOUCODES = "18MO"

    End Select


    End Sub

    This works great but I have to click on the record for it to run/update the ulticoucodes field.

    Is there a way to loop through the entire "resultsCourse" field to test if condition is met and uopdate the ulticodes field if it is?

    Thanks in advance

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Perhaps the following code in the form's On Current event would work:
    Code:
    If [ResultsCourse] = "12 month competency" Then
      ULTICOUCODES = "12MO"
    ElseIf [ResultsCourse] = "18 month competency" Then
      ULTICOUCODES = "18MO"
    End If
    You would need to click through every record though.
    Alternatively, you could create a function that opens a recordset of the data and and moves from the first record to the last record and make changes to each record as required before moving to the next record.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. CASE STATEMENT or IF-ELSE-THEN? HELP
    By Shakenaw in forum Access
    Replies: 9
    Last Post: 06-08-2015, 11:24 AM
  2. using two criteria in one case statement
    By chessico in forum Access
    Replies: 5
    Last Post: 03-14-2012, 03:25 PM
  3. if or case statement and how
    By Dannat in forum Queries
    Replies: 1
    Last Post: 01-31-2012, 10:35 AM
  4. Help with Select Case statement
    By focosi in forum Access
    Replies: 4
    Last Post: 08-09-2011, 12:01 AM
  5. Case Statement Syntax
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 1
    Last Post: 11-16-2010, 07:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums