Results 1 to 6 of 6
  1. #1
    terry6582 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2017
    Location
    TN
    Posts
    21

    using VBA in a module

    I have a form "register_sub_form1" with fields "chapter_no", chapter" and "zone". I would like to be able to enter the "chapter_no" and have it populate the "chapter_name" and "zone" fields.

    if [chapter_no] = 0 then [chapter_name] = state staff and [zone] = 0
    else if [chapter_no] = 0 then [chapter] = handicapped and [zone] = 10
    endif

    Thanks for your help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Should not duplicate data into multiple tables. All you need to save is the chapter_no. Retrieve other info in queries that join tables.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    don't understand your code both require chapter_no to be 0, so only the first part of the statement will fire. Suspect what you want is

    Code:
    if chapter_no = 0 then 
       chapter_name= "state staff"
       zone = 0
    else
       chapter = "handicapped" 
       zone = 10
    end if

  4. #4
    terry6582 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2017
    Location
    TN
    Posts
    21
    Alex,

    There a many more chapter numbers. (0 - 30)

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    in that case use Select Case

    Code:
    select case chapter_no
       case 0
            chapter_name= "state staff"
            zone = 0
        case 1
           chapter = "handicapped" 
           zone = 10
        case 2
            ….
    
     
    end select
    Without knowing your design probably better to store chapter number, name, zone etc in a table rather than hardcoding it

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    YES, if you don't already have one, build a table for Chapters. Then just save Chapter_No into Register as foreign key.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Run a second module after 1st
    By natonstan in forum Macros
    Replies: 5
    Last Post: 03-03-2017, 04:54 AM
  2. What is Module?
    By glen in forum Modules
    Replies: 1
    Last Post: 09-14-2012, 09:11 AM
  3. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM
  4. Run a Module
    By mchadwick in forum Modules
    Replies: 7
    Last Post: 09-02-2011, 09:24 AM
  5. Replies: 4
    Last Post: 05-16-2011, 04:58 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