Results 1 to 13 of 13
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Building Array


    I have developed an array referenced in the code below. What I want to happen is if the user enters one of the user IDs in the array, a report will display. If the user ID does not match, another form will load. However, I keep getting a "Type Mismatch" error. Any ideas?
    Code:
        Dim strText0 As String
        strText0 = Form_frmRVNumber.Text0.Value
        Dim strRVNum() As String
        ReDim strRVNum(0 To 11) As String
            strRVNum(0) = "User1"
            strRVNum(1) = "User2"
            strRVNum(2) = "User3"
            strRVNum(3) = "User4"
            strRVNum(4) = "User5"
            strRVNum(5) = "User6"
            strRVNum(6) = "User7"
            strRVNum(7) = "User8"
            strRVNum(8) = "User9"
            strRVNum(9) = "User10"
            strRVNum(10) = "User11"
            strRVNum(11) = "User12"
        If strText0 Is strRVNum Then
            Dim stDocName As String
     
            stDocName = "rptTimeTrack"
            DoCmd.OpenReport stDocName, acPreview
            DoCmd.Maximize
        End If

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This line: If strText0 Is strRVNum Then
    ... does not seem to be referencing the array!

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Forgive me for asking.....How should I reference the array? I am not familiar with arrays.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The same way you referenced it when you were initializing it. strRVNum(n)

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I apologize for that bout of...incompetance... However, I changed the code to the following:
    Code:
        Dim strText0 As String
        strText0 = Form_frmRVNumber.Text0.Value
        Dim strRVNum() As String
        ReDim strRVNum(0 To 11) As String
            strRVNum(0) = "User1"
            strRVNum(1) = "User2"
            strRVNum(2) = "User3"
            strRVNum(3) = "User4"
            strRVNum(4) = "User5"
            strRVNum(5) = "User6"
            strRVNum(6) = "User7"
            strRVNum(7) = "User8"
            strRVNum(8) = "User9"
            strRVNum(9) = "User10"
            strRVNum(10) = "User11"
            strRVNum(11) = "User12"
        If strText0 = strRVNum() Then
            Dim stDocName As String
     
            stDocName = "rptTimeTrack"
            DoCmd.OpenReport stDocName, acPreview
            DoCmd.Maximize
        End If
    And I still get the "Type Mismatch" error....

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You need an index number to point to a legal element of the array.
    strRVNum(n)
    Replace the n with a number from 0 to 11.

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    RuralGuy - Please ignore my last post. However, I changed this line:
    Code:
    If strText0 = strRVNum() Then
    to
    Code:
    If strText0 = strRVNum(4) Then
    for argument sake. It did work as expected when I entered User5 it worked as expected. However, I want to check for any one of those users, User1 through User12. How would I go about doing that?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I curious, why did you pick an array instead of a Select Case or string of If ElseIf statements?

  9. #9
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Because I thought array would be the best way. I am open to other methods if they are easier, or make more sense. It has been a while since I did some serious VB coding and I cannot remember how to do a Select Case. I thought about doing a string of If ElseIf statements but thought an array would cut down on the coding...

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Code:
    Select Case strText0
           Case "User1"
              '.. do this
           Case "User2"
              '.. do this
           Case Else
              '.. do this
    End Select

  11. #11
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    RuralGuy - Thank you! That worked perfectly. Much appreciated.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You're welcome. All three way would have worked but each method requires different code. I find Select Case easier to read and maintain.

  13. #13
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I am inclined to agree with you. I had completely forgotten about Select Case. Thanks again.

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

Similar Threads

  1. need some advice building DB (noobie)
    By sureshot in forum Access
    Replies: 2
    Last Post: 10-12-2009, 09:49 AM
  2. Problem with building SQL string (VBA)
    By cdpeck in forum Programming
    Replies: 1
    Last Post: 09-15-2009, 04:25 AM
  3. Building a Difficult DateDiff Expression
    By jma108 in forum Queries
    Replies: 0
    Last Post: 06-15-2009, 12:39 PM
  4. How to use array? [ solved] Thanks.
    By wasim_sono in forum Programming
    Replies: 0
    Last Post: 10-20-2006, 12:00 AM
  5. building a distribution package
    By BevA in forum Access
    Replies: 0
    Last Post: 05-26-2006, 07:04 AM

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