Results 1 to 5 of 5
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    update multiple fields

    All,


    Using access 2003; Im trying to update a field based on another field. i.e.
    using an update query.
    Code:
     
    If [Shipper State]= ME, VT, NH, CT, N,J, MD, DC,VA, NC,TN SC, MA, DE, RI [Shipper Country] = NORTHEAST
    ELSEIF [Shipper State] = OK, AR,TX,LA,MS,AL, GA, FL [Shipper Country]=SOUTHEAST
    ELSEIF [Reciever State] =, VT, NH, CT, N,J, MD, DC,VA, NC,TN SC, MA, DE, RI [Reciever Country] = NORTHEAST
    ELSEIF [Reciever State]= OK, AR,TX,LA,MS,AL, GA, FL [Shipper Country]=SOUTHEAST
    ENDELSE
    I have not done a if or case statement in a long while. Can anyone guide me based on my criteria above. Should I put this in a module to call before my append query? Thanks

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Here is the syntax for Case Select. Looks like your perfect for this scenario.

    http://www.techonthenet.com/access/f...anced/case.php

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ok. I don't remember how to use this but I'll give it a shot.

    Code:
    Public Function
    Dim
    Select Case[?]
    Case [Shipper State]”ME”
    [Shipper Country]=NORTH
    Case [Shipper State]”VT”
    [Shipper Country]=NORTH
    Case [Shipper State]”SC”
    [Shipper Country]=NORTH
    End Select
    Still fuzzy. Not sure if this is going in the correct direction, I assume I have to put this in a module to call. I really need help please starting this off.
    Thanks

  4. #4
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    You can put it in an after update event or even on an onclick event for a button. The question mark should be populated with the field name you are testing.
    Code:
    Public Function
    Dim
    Select Case[Shipper State]
    Case ”ME”
    [Shipper Country]="NORTH"
    Case ”VT”
    [Shipper Country]="NORTH"
    Case ”SC”
    [Shipper Country]="NORTH"
    End Select
    Alternatively, you could do it this way also

    Code:
    Public Function
    Dim
    Select Case[Shipper State]
    Case ”ME”, "VT", "SC"
    [Shipper Country] = "NORTH"
    Case "FL", LA", "AL"
    [Shipper Country] = "SOUTH"
    End Select

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ok. Havent done this in a while but I'm having problems with my Case statement. I put it in a function called update because that's what Im doing in a table. When I try to compile it; the Function line turns red pointing out the fields. I don't know if this works because I cant get past the comile error.

    Code:
    Option Compare Database
    Function Update([Shipper State]As String,[Shipper Company]As String, [Shipper Country]As String, [Recipient Company]As String, [Recipient Country] As String)
    On Error GoTo Err_Update
    Select Case [Shipper State]
    Case "ME", "VT", "NH", "NY", "CT", "NJ", "MD", "DC", "VA", "NC", "TN", "SC", "MA", "DE", "RI"
    [Shipper Country] = "US NORTHEAST REGION"
    Case "AR", "TX", "LA", "MS", "AL", "GA", "FL"
    [Shipper Country] = "US SOUTH REGION"
    Case "ND", "SD", "NE", "KS", "MN", "IA", "MO", "WI", "IL", "IN", "OH", "MI", "KY", "WV", "PA"
    [Shipper Country] = "US CENTRAL REGION"
    Case "WA", "OR", "CA", "ID", "NV", "MT", "WY", "UT", "CO", "AZ", "NM", "AK", "HI"
    [Shipper Country] = "US WEST REGION"
    End Select
    Select Case [Recipient State]
        Case "ME", "VT", "NH", "NY", "CT", "NJ", "MD", "DC", "VA", "NC", "TN", "SC", "MA", "DE", "RI"
        [Recipient Country] = "US NORTHEAST REGION"
        Case "AR", "TX", "LA", "MS", "AL", "GA", "FL"
        [Recipient Country] = "US SOUTH REGION"
        Case "ND", "SD", "NE", "KS", "MN", "IA", "MO", "WI", "IL", "IN", "OH", "MI", "KY", "WV", "PA"
        [Recipient Country] = "US CENTRAL REGION"
        Case "WA", "OR", "CA", "ID", "NV", "MT", "WY", "UT", "CO", "AZ", "NM", "AK", "HI"
        [Recipient Country] = "US WEST REGION"
    End Select
    Select Case [Recipient Company]
        Case "Atlas*" Or "NORTH AMERICAN SERVICE CENTER"
        [Recipient Company] = "ATLAS COPCO COMPRESSORS"
    End Select
    Select Case [Shipper Company]
        Case "Atlas*" Or "NORTH AMERICAN SERVICE CENTER"
        [Shipper Company] = "ATLAS COPCO COMPRESSORS"
    End Select
    Exit_Update:
        Exit Function
     
    Err_Update:
            MsgBox Err.Number & " - " & Err.Description
            Resume Exit_Update
            Exit Function
    End Function
    Please help.
    Thanks

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

Similar Threads

  1. Update Multiple Fields based on Selection (inTable)
    By aguestnga in forum Database Design
    Replies: 3
    Last Post: 11-03-2011, 04:17 PM
  2. Replies: 1
    Last Post: 08-30-2011, 07:35 AM
  3. Update Multiple fields according multiple criterias
    By denis.m in forum Programming
    Replies: 1
    Last Post: 02-21-2011, 11:03 AM
  4. Replies: 15
    Last Post: 10-14-2010, 12:22 PM
  5. Replies: 1
    Last Post: 02-03-2010, 09:17 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