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

    VBA code using if then else statements

    Have a db with a form " registration" with a field "vendor" this is a check box "yes/no". I would like to have the db make a decision to open another form "vendor pre-reg" if vendor is checked or return to the main menu "switchboard entry" if vendor is not checked.



    If tried the following module but it will not work:

    if [vendor] = yes then goto [vendor pre-reg]
    else if [vendor] = no then go to [switchboard entry]
    endif

    I am new to using modules in Access. I am using 2010 version.

    Any help is appreciated.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    You are mixing syntax types and making it more complicated than you need to, try

    Code:
    if Me.vendor = true then 
            docmd.openform "vendor pre-reg"
    else 
            docmd.openform "switchboard entry"
    end if
    You don't need an else if with only two conditions, it's either true or not.

    Me.Vendor refers to Me = The current form, and .Vendor a control on that form.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    terry6582 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Dec 2017
    Location
    TN
    Posts
    21
    That worked great.

    Next issue.

    I have a form "register_sub_form1" with fields "chapter_no", chapter_name" 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.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    is that not the same problem you started a thread for here? https://www.accessforums.net/showthread.php?t=74846

  5. #5
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Sure looks like it - two recommendations were made, and storing the data in a table and referencing just the table and primary key is the "correct" way to store this.

    If storing the data is a requirement (and it shouldn't be unless this data changes over time) then simply bring those values into a combo box based around Chapter_No and set them from hidden column values after the combo is updated.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Using If statements
    By Joyce Carney in forum Queries
    Replies: 2
    Last Post: 07-06-2014, 05:27 PM
  2. IIF() statements
    By ajetrumpet in forum Tutorials
    Replies: 0
    Last Post: 06-17-2011, 06:51 PM
  3. Replies: 0
    Last Post: 07-09-2010, 06:22 AM
  4. SQL statements from VBA
    By John Southern in forum Programming
    Replies: 12
    Last Post: 05-16-2010, 01:07 PM
  5. If statements
    By Ezeecopy in forum Access
    Replies: 0
    Last Post: 03-24-2009, 04:54 AM

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