2014-06-14 72 views
0

我是VBA的初學者,我想知道如何將選擇語句複製到數組。我能怎麼做? 我試圖做一些事情,但我不能complite。訪問VBA複製選擇語句到數組

Private Sub Komut485_Click() 
Dim a() As String 

'Dim a() As Integer 
'abc = Me.talep_kayit_no.Value 
'MsgBox abc 


For sayac = 1 To 5 

a(sayac) = "SELECT [3_gh_odemeler].[gh_no] FROM 3_gh_odemeler WHERE [3_gh_odemeler].[gh_no] =" & Me.talep_kayit_no.Value & ";" 

sayac = sayac + 1 

MsgBox a(1) 


Next 


End Sub 
+0

替換'暗淡()作爲String'用'變暗一個(1〜5)作爲String'並刪除線'sayac = sayac + 1' –

回答

0

我想數組總是從0開始,因此會使用第一個位置(0)作爲正確的位置。

Dim intArraySize as integer 
dim a() as string 
intArraySize =5 

redim a(intArraySize) 

For sayac = 0 To intArraySize 

a(sayac-1) = "SELECT [3_gh_odemeler].[gh_no] FROM 3_gh_odemeler WHERE [3_gh_odemeler].[gh_no] =" & Me.talep_kayit_no.Value & ";" 

sayac = sayac + 1 

MsgBox a(1) 


Next 


End Sub 
+0

1)是什麼的雙遞增'點sayac' ? 2)在'a(sayac-1)=「SELECT ..」'這一行'sayac = 0'是什麼? –

+0

@ 1 owww對不起我的錯,當然需要刪除雙倍遞增。好點子。因此,刪除'sayac = sayac + 1' –

+0

也'我以爲數組總是從0開始 - 而不是實際。 [Option Base Statement](http://msdn.microsoft.com/en-us/library/aa266179(v = vs.60).aspx) –