Aren't the elements of a variant, variants too? (1 Viewer)

prabha_friend

Prabhakaran Karuppaih
Local time
Tomorrow, 03:42
Joined
Mar 22, 2009
Messages
771
Code:
Public Function RefreshLinks()
Dim myDiag As FileDialog
Dim Files As Variant
Dim Washes As Variant
Dim Temp As Variant
 Files = Array("DEU", "DDE")
Washes = Array("Business Wash", "Corporate Wash", "Coupon Wash", "Dividend Wash")
Set myDiag = FileDialog(msoFileDialogFilePicker)
ReDim Temp(1)
 For Each [B][COLOR=red][I]Temp(0)[/I][/COLOR][/B] In Files
    With myDiag
        .Show
    End With
    Select Case Temp(0)
        Case "DEU"
            For Each Temp(1) In Washes
                MsgBox CurrentDb.TableDefs(Temp(1) & "_DEU").Name
            Next element
        Case "DDE"
    End Select
Next element
 End Function
Why am I getting a following error:
Compile error:
Variable required - can't assign to this expression

But Logically its right right? means in a variant array: all of its elements are also variant. But can't I able to use it to assign a variable while looping..?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:12
Joined
May 7, 2009
Messages
19,169
should be:

Dim temp2 as variant
For Each Temp In Files
With myDiag
.Show
End With
Select Case Temp
Case "DEU"
For Each Temp2 In Washes
MsgBox CurrentDb.TableDefs(Temp2 & "_" & temp).Name
Next element
Case "DDE"
End Select
Next element
 
Last edited:

prabha_friend

Prabhakaran Karuppaih
Local time
Tomorrow, 03:42
Joined
Mar 22, 2009
Messages
771
should be:

For each Temp In Files

Hi Arnel,
Thanks to your reply. Please see in the code that there is one more loop needed to looped through an another array. Is there any possibility that I can use the elements of the temp (instead of the temp itself) to successfully loop both of the arrays and read the currently element's value of both them?

Thanks to you again Arnel. I want to know why I am not able to assign a value in a looping scenario though it is a variant.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:12
Joined
May 7, 2009
Messages
19,169
see my post, i added another variant variable temp2.
i don't have the answer to your question, its just the way it is.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:12
Joined
Sep 12, 2006
Messages
15,614
ignore. more complex than I thought.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:12
Joined
Feb 28, 2001
Messages
27,001
Perhaps I am being a bit more dense than normal but I don't see where there is any syntax suggesting that Temp is a structure and therefore, I don't see why the two explicit arrays would be associated intimately with the Temp variant or variant array.

I HAVE used arrays and structures in both simple combinations: arrays containing structures and structures comprised of multiple arrays. What I see doesn't look at all like what I used in the other cases.

What were you originally trying to do?
 

prabha_friend

Prabhakaran Karuppaih
Local time
Tomorrow, 03:42
Joined
Mar 22, 2009
Messages
771
Done this way:
Code:
Public Function RefreshLinks()
'Function to Relink the Files
Dim vrtFiles As Variant 'Types of Files
Dim vrtWashes As Variant    'Types of Washes
Dim vrtTemp As Variant  'Temporaray Variable
Dim myDiag As FileDialog    'Dialog box to select File/Folder
 vrtFiles = Array("DEU", "DDE")
vrtWashes = Array("Business Wash", "Corporate Wash", "Coupon Wash", "Dividend Wash")
vrtTemp = Array(0, 0)
Set myDiag = FileDialog(msoFileDialogFilePicker)
 Do While vrtTemp(0) <= UBound(vrtFiles) 'Delete the Linked the Table and Relink it
    
    With myDiag
        .Title = "Select the Appropiate File for the Table : " & vrtFiles(vrtTemp(0))
        .Show
    End With
    
    Select Case vrtFiles(vrtTemp(0))
        Case "DEU"
            Do While vrtTemp(1) <= UBound(vrtWashes)
                DoCmd.DeleteObject acTable, vrtWashes(vrtTemp(1)) & "_DEU"
                Call LinkTheTable(vrtWashes(vrtTemp(1)) & "_DEU", myDiag.SelectedItems(1))
                vrtTemp(1) = vrtTemp(1) + 1
            Loop
        Case "DDE"
            DoCmd.DeleteObject acTable, "DDE"
            Call LinkTheTable("DDE", myDiag.SelectedItems(1))
    End Select
    
    vrtTemp(0) = vrtTemp(0) + 1
 Loop
End Function

Sorry for a very late reply :(
 

Users who are viewing this thread

Top Bottom