Results 1 to 30 of 30

Thread: And or If Statement

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    And or If Statement

    I need to have the following code state "0A" or "0B" (zero A or zero B). Please see the specific lines in bold.
    Any help will greatly be appreciated.

    If bRetirementNo0 = False And sRetirementNo < "50000000" Then
    If lReportcode = "010" Then
    StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    ElseIf lReportcode = "020" Then
    sRetirementNo = "0A" & Mid(sRetirementNo, 2) StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    End If

    sSql = "INSERT INTO tl_PR_NYSRetirementReport "
    sSql = sSql & "(fknCompany, fknEmployee, sName, sRetirementNumber, sSocialSecurityNumber, nTier, cGrossSalary )"
    sSql = sSql & "SELECT DISTINCTROW "
    sSql = sSql & "td_PREmployees.fknCompany, "
    sSql = sSql & "AND ((td_PRCalculatedHistory.ynVoided)=False) "
    sSql = sSql & "AND ((IIf(Not IsNull([sRetirementAccountNumber]) "
    sSql = sSql & "And Left$([sRetirementAccountNumber],2)='0A',True,False))"
    If Me!opgReportType = 1 Then
    sSql = sSql & "=False)) "
    Else
    sSql = sSql & "=True)) "
    End If

  2. #2
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: And or If Statement

    what is it currently doing? and under what condtions does it need to say 0A and when does it need to say 0B?
    and it would make things easier to read if you put some vb code tags around the code portion

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    Sorry for the lack of tags.
    The code is suppose to determine if an employee's retirement number begins with an "0A" and if it does, it's to be displayes on report code 20. If it doesn't, then it's to be displayed on report 10.
    Both reports, by code number are exported to an ASCII file.
    I was hoping to add some additional code that would instruct the program to include "0B" as well as "0A" and follow the same conditions described in the code.

  4. #4
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: And or If Statement

    i think i know what you mean... i'm just not sure where you are storing the 0A or B0
    if you use something like

    vb Code:
    1. If lReportcode = "010" Then
    2. StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    3. ElseIf lReportcode = "020" And Condition1 Then
    4. sRetirementNo = "0A" & Mid(sRetirementNo, 2) StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    5. ElseIf lReportcode = "020" And Condition2 Then
    6. sRetirementNo = "0B" & Mid(sRetirementNo, 2) StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    7. End If

    and then replace Condition1 and Condition2 with the conditions for those instances when you want to output 0A and 0B respectivly

    alternativly you can use nested if statements like this

    vb Code:
    1. If lReportcode = "010" Then
    2. StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    3. ElseIf lReportcode = "020" Then
    4. If Condition1 Then
    5. sRetirementNo = "0A" & Mid(sRetirementNo, 2) StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    6. ElseIf Condition2 then
    7. sRetirementNo = "0B" & Mid(sRetirementNo, 2) StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
    8. End If
    9. End If

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    I very much appreciate the suggested coding, but it did not work. I know that I need to provide more information which I hope to have done in the attachment (I tried uploading the form that contains the original code that includes one of your suggestions).
    The two areas that contain the sorting are under 'Registration Number and 'Output to ASCII file
    Thanks again for you efforts.
    Attached Files Attached Files

  6. #6
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: And or If Statement

    when I try to open the file in access it gives me a security warning and says it may be a macro virus, any ideas what would be causing that?
    and also, since you are doing visual basic embedded in Access, there is a subforum for VB code in office applications development (http://www.vbforums.com/forumdisplay.php?f=37) so if we can't get your problem solved here, you could try there

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    The security warning is generated by Access. Open Access - Tools - Macro - Security.
    If your Macro security is set to Med or High, you'll get the warning message.
    The form/code that I sent you has several macro references.....but no virus.

  8. #8
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: And or If Statement

    ok, i'll take a look when i get home... i have never really used access so I wasnt sure what the warning was about

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    Sorry for the delay in following up. I've been trying to make your suggested code work, and have had some limited success. I need to ask what you mean by replacing Condition1 / Condition2 with the condition for those instances. Also, all values are store in temporary tables for use by two different reports. Appreciate any insight.

  10. #10
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: And or If Statement

    the conditon1 and condition2 need to be replaced with boolean statements, but I wasn't sure what the statements were. condition1 = conditions when to output 0A before it and condtion2 = conditions when to output 0B before it. If you do not know/cannot figgure out the boolean expression for these cases, let me know what the conditions are in words, and I can help you formulate it into a boolean expression

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    I appreciate your continued help....and apologize for being so dense. I believe that the statement(s) you are looking for is contained in this section of code
    HTML Code:
    If bRetirementNo0 = False And sRetirementNo < "50000000" Then
                    If lReportcode = "010" Then
                        StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
                    ElseIf lReportcode = "020" Then
                        sRetirementNo = "0A" & Mid(sRetirementNo, 2)
                        StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
                    End If
    The bRetirementNo0 is Dim as Boolean. Not sure it that helps. This section of code takes the retirement number entered on a form and places it on a hard copy report and then creates an ASCII file. The entire length of the entry is 8 digits. I've tried several renditions of statments, but have had limited success (meaning that I can only get 0A's or 0B's on one report, not both). I haven't a clue at this point as to how to make this thing happen.

  12. #12
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: And or If Statement

    ok i can see the contition for 0A now, but where do you give it 0B?

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    I don't have any condition for 0B. This is something new that needs to be added to the code and resulting ACSII file.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    I can't seem to create a new condition that allows the "0B" entry as well as the "0A". Any resulting reports from code changes that I make only reflect the "0A". Any help with creating the additional condition will greatly be appreciated.

  15. #15

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    Yes. The code is behind a form.

  17. #17

  18. #18
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: And or If Statement

    how do you tell if the item is an OB item? or an OA item, does it have a different reportcode?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    "0A" and/or "0B" belong to Report Code 20 only. Any other eight digit numbers belongs to Report Code 10. The user assigns the eight digit number when entering the employee's information. This eight digit number determines which report prints the respective employee's information.

  20. #20
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: And or If Statement

    so if both 0A and 0B are reportcode 20, how can you tell which are 0A and which are 0B? you have give no explanation as to how you can identify each
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    The code now states that Report 20's registration number begins with "0A". Any other number belongs to Report 10. The code works as is. Now, I want registration number "0B" to belong to Report 20 along with "0A". I can't seem to code any conditions or "and,or" statements that will make this happen. What am I missing?

  22. #22
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: And or If Statement

    Now, I want registration number "0B" to belong to Report 20 along with "0A"
    which variable holds the registration number?
    as it looks like you are addng the 0A in your code, how do you determine if a item with reportcode 20 is 0A or 0B?

    edit: this is what everyone asks.... how can you tell which is 0A or 0B?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    sRetirementNo contains the registration number. The code now states:
    Code:
    "Elseif IReportCode="020" then sRetirementNo="0A".
    The user selects which report to generate by clicking on the Report 20 radio button located on a form. The system then looks at each employee to determine if their registration number begins with a "0A". If so, they will be listed on the report. If not, they belong to Report 10. This sceanario works fine. What I'm trying to do is add an additional variable "0B". If employee's registration number begins with "0B" (in additiona to "0A") they too should be reflected on Report 20.

  24. #24
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: And or If Statement

    "Elseif IReportCode="020" then sRetirementNo="0A".
    this code sets the sretirmentno to 0A if reportcode = 20, but from what you say above it looks as if you want to set the reportcode if the sretirementno contains 0A or 0B
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  25. #25

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    Correct!

  26. #26
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: And or If Statement

    try like this
    vb Code:
    1. If InStr(sRetirementNo, "0A") > 0 Or InStr(sRetirementNo, "0B") > 0 Then IReportCode = "020"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  27. #27

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    Thank you for your time and the suggested code. I inserted your suggestion as follows but the resulting report did not reflex registration numbers that began with "0A" or "0B". The first two places of the registration code now reflects "00". Perhaps I placed your suggested code in the wrong place?
    Code:
    If bRetirementNo0 = False And sRetirementNo < "50000000" Then
                    If lReportcode = "010" Then
                        StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
                    ElseIf lReportcode = "020" Then
                        If InStr(sRetirementNo, "0A") > 0 Or InStr(sRetirementNo, "0B") > 0 Then lReportcode = "020"
                        'sRetirementNo = "0A" & Mid(sRetirementNo, 2)
                        StrASCIIText = StrASCIIText & String(8 - Len(sRetirementNo), "0") & Trim(sRetirementNo)
                    End If

  28. #28
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: And or If Statement

    your request and your previous code do not match, there is something that we can not see at all about what you are wanting to do

    your previous code sets the "0A" into the string, and is done when reportcode = 20, it does not get the 0A from the retirement number, it looks to me as if you need to find where the 0B is stored so you can determine which records are 0B records
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  29. #29

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    I double checked and found that the registration number is indeed sRetirementNo. A statement in the coded states:
    Code:
    sRetirementNo = CheckNumeric(rsRetirement("sRetirementNumber"))
    I've attached the form that contains all the code pertaining to my request. I "flaged" the specific section of code (to the left) with VINCENTD.
    Attached Files Attached Files

  30. #30

    Thread Starter
    Junior Member
    Join Date
    Nov 2007
    Posts
    16

    Re: And or If Statement

    To clarify further, the "OA" registration number, as well as the "0B" registration number are both entered by the user and stored in the same table. The entire registration number is eight digits long. The only difference between Report 10 and Report 20 is that the registration number for Report 20 begins with a "0A" (as shown in the code). I'm trying to add registration numbers that begin with "0B" for Report 20 as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width