Results 1 to 11 of 11
  1. #1
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15

    Help for If Then Statement

    First line is wrong ... Any help would be appreciated

    If [CACorIDcard] = -1 And [IDResaon] = "Lost" Then



    DoCmd.OpenForm "frmCE_LostCAC"

    Else
    End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    What does "wrong" mean - error message, wrong result, nothing happens?

    Is IDResaon a number type field?

    Should "IDResaon" be spelled "IDReason"?
    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
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    167
    If [CACorIDcard] = -1 And [IDResaon] = "Lost" Then

    Are [CACorIDcard] and [IDReason] control names on your form? If so, you need to prefix those with Me! (points to the form you're running your code from).

    If Me!CACorIDcard=-1 And Me!IDreason = "Lost" Then
    DoCmd.OpenForm "frmSomeForm"
    ELSE
    msgbox "Sorry!",vbokonly
    End If

  4. #4
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15
    Still not happening (form doesn't appear).
    IDReason is a text field
    CACorIDCard is a Yes/No field

  5. #5
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15
    If I use one field, it works. I believe the problem has something to do with how the fields are connected. Is "And" correct?

  6. #6
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    167
    Can you post just this form and the tables it needs? then we can see what's wrong.

  7. #7
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15

    Screenshot attached

    I couldn't attached the file (too big), even after deleting all the other forms, queries, reports, etc.

    I attached a screenshot.
    Attached Thumbnails Attached Thumbnails Capture.jpg  

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,980
    That would lead me to believe the code is working, just that you do not have the combination to open your form. Walk your code line by line with breakpoints and inspect your values. Don't just assume they are correct.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,980
    You would need to show the record where those controls are correct, not design view.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15
    The code is run (After update in the IDReason)

  11. #11
    JJPetersen1 is offline Novice
    Windows 8 Access 2016
    Join Date
    Jan 2020
    Posts
    15
    The break points suggestion was the key. The IDReason is a linked table. I was referring to the field in the table.

    THANK YOU

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

Similar Threads

  1. Replies: 5
    Last Post: 11-01-2021, 08:09 AM
  2. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  3. 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
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. Help with IF statement
    By mkallover in forum Programming
    Replies: 7
    Last Post: 01-04-2011, 04:47 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