Results 1 to 6 of 6

Thread: Validating for empty datafields

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    11

    Validating for empty datafields

    Hi I got a problem whereby my boss has failed to maintain the AS400 server's database. This means that I will have field "elrsnc" being empty and causing major problem to my work.

    Elrsnc is suppose to represent a value of 1-11. So base on the selected value i will insert a strFieldName (example value 1, strFieldname ="XRSN01") into another table empexit. My problem is if Im running my codes as of those below, how should I validate for rsCode.Fields("elrsnc") = ""


    sql2 = "select empno, edcode, elyyyy, elmm, eldd, elrsnc from EMPloyee " & _
    "where empno = '" & empno & "'"

    rsCode.Open sql2, cn, adOpenKeyset, adLockOptimistic

    intELRSNC = CInt(rsCode.Fields("elrsnc"))

    Select Case intELRSNC

    Case 1: strFieldName = "XRSN01"
    Case 2: strFieldName = "XRSN02"
    Case 3: strFieldName = "XRSN03"
    Case 4: strFieldName = "XRSN04"
    Case 5: strFieldName = "XRSN05"
    Case 6: strFieldName = "XRSN06"
    Case 7: strFieldName = "XRSN07"
    Case 8: strFieldName = "XRSN08"
    Case 9: strFieldName = "XRSN09"
    Case 10: strFieldName = "XRSN10"
    Case 11: strFieldName = "XRSN11"

    End Select

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    I'm not sure what you are asking. Do you mean how do you check if the field is empty?

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    11
    Yup how do i check when field "elrsnc" is empty? If its empty i need to insert strFieldName = "" into the database table else i need to run my select case. Do you get what i mean? Thanks

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    11
    My elrsnc will potentially be empty. Then when I try to CInt it
    will return me an error

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    You just need to add some error handling then.
    VB Code:
    1. On Error Resume Next
    Or, maybe not the best, but:
    VB Code:
    1. On Error Goto Err:
    2. intELRSNC = CInt(rsCode.Fields("elrsnc"))
    3.  
    4. Select Case intELRSNC
    5.  
    6. Case 1: strFieldName = "XRSN01"
    7. Case 2: strFieldName = "XRSN02"
    8. Case 3: strFieldName = "XRSN03"
    9. Case 4: strFieldName = "XRSN04"
    10. Case 5: strFieldName = "XRSN05"
    11. Case 6: strFieldName = "XRSN06"
    12. Case 7: strFieldName = "XRSN07"
    13. Case 8: strFieldName = "XRSN08"
    14. Case 9: strFieldName = "XRSN09"
    15. Case 10: strFieldName = "XRSN10"
    16. Case 11: strFieldName = "XRSN11"
    17.  
    18. End Select
    19. Exit Sub 'or function if its a function
    20. Err:
    Does the same really...

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    11
    If Im going to insert the strFieldName as below.

    sql3 = "insert into empexit(XEMPNO,xdcode,xlyyyy, xlmm, xldd, " & strFieldName & "

    Is this way of error handling correct?

    On Error Goto Err:
    intELRSNC = CInt(rsCode.Fields("elrsnc"))

    Select Case intELRSNC

    Case 1: strFieldName = "XRSN01"
    Case 2: strFieldName = "XRSN02"
    Case 3: strFieldName = "XRSN03"
    Case 4: strFieldName = "XRSN04"
    Case 5: strFieldName = "XRSN05"
    Case 6: strFieldName = "XRSN06"
    Case 7: strFieldName = "XRSN07"
    Case 8: strFieldName = "XRSN08"
    Case 9: strFieldName = "XRSN09"
    Case 10: strFieldName = "XRSN10"
    Case 11: strFieldName = "XRSN11"

    End Select
    Exit Sub
    Err:
    strFieldName = ""
    End Sub

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