Results 1 to 8 of 8
  1. #1
    Elbows is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    8

    IF Statement in a Macro

    I wish to do the following by using a macro. I cannot write VBA.

    Open a form that has one field.

    If the text in the field says yes then open the yes form, if not then open the no form.


    Thanks.

    What I am actually trying to do is to populate a table automatically.
    I receive an Excel sheet like so:
    1 Data
    Data
    Data
    2 Data
    Data
    3 Data
    Im want it (through an automated process) to end up looking like this, ie filling in the blanks:
    1 Data
    1 Data
    1 Data
    2 Data
    2 Data
    3 Data

    I can do it through a series of queries but it is a little untidy as it just creates a null expression and I have to "stop all macro's"
    As I mentioned I don't do VBA.
    I have done this before in Access 2003 but I've lost the database that it was on.
    I basically did it by opening a form. If it was yes it opened the Yes form (which triggered the loop) or No which triggered the "Done" form

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    Why not VBA? Time to learn?

    I don't see any way to do this with macros except for executing the series of queries as you are doing.
    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
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I agree with June, that VBA in Access (or even Excel) is the best way to go, if you are looking for automation.

    A manual, but fairly quick way to go about it is to fix the file manually in Excel like this.
    1. Find the first blank entry (let's say it is cell A3), and enter a formula in that cell referencing the cell above it (=A2).
    2. Highlight the cell with the formula you just entered and select the Copy button.
    3. Highlight the rest of that column, down as far as the bottom of your data.
    4. Press F5 (Go To) and press the "Special" button
    5. Select the "Blanks" radio button, and press "OK".
    6. Hint you "Enter" button on your keyboard.

    This should "AutoFill" all your missing entries.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    Oh Doh! I should have seen that prepping the Excel first is probably simplest approach.
    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.

  5. #5
    Elbows is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    8
    Thanks people I agree VBA is the way to go. I've ordered the book !!!!!!
    However If you could answer the first part of my question :

    Open Form1 that has one field (Field1) from Table1.

    If the text in Field1= "yes" then close Form1 and open Form2, if not then close Form1 and open Form3.

    I've got the first bit in the macro but cant figure out how to you use (or what to write) in the IF Statement after the "Open Form1". I know it should look like [Form1]![Field1}="Yes" but it doesn't work.

    Any further advice is much appreciated.




  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    You show a } instead of ].

    I don't use macros, only VBA.
    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.

  7. #7
    Elbows is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    8
    That was just typo.

    I know it should look like [Form1]![Field1]="Yes" but it doesn't work.


    Would appreciate somebody who DOES use Marco's to reply. If nothing else but to save space!!!

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,615
    I don't routinely use macros in my projects (used macros only twice) but have debugged a few dbs that use them. Unfortunately, I have to analyze the db directly. If you want to provide, follow instructions at bottom of my post.
    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. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. How to issue a GRANT statement from a macro
    By xfp39024 in forum Access
    Replies: 2
    Last Post: 06-15-2012, 11:48 AM
  3. Replies: 2
    Last Post: 05-05-2012, 02:34 AM
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. Replies: 0
    Last Post: 01-12-2011, 12:43 PM

Tags for this Thread

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