0
我有循環遍歷數組成員數組並檢索每個記錄的代碼。每次我都需要使用返回記錄數爲12的計數。但是,一旦保存計數的變量被設置,它將不會在下一次調用時重置。它也從第一個到最後一個記錄「跳」,而不是循環遍歷每個記錄。換句話說,如果存在由記錄返回4條記錄,將執行第一個和最後一個,然後給出「沒有當前記錄」錯誤這裏是我的代碼:MS Access 2010 VBA整數變量不會在循環中更改
Dim x As Integer
For i = 1 To intMembers
strGetMemberInfo = "SELECT PatientRecords.[Medication Name], PatientRecords.[First Name], PatientRecords.[Last Name],PatientRecords.[doc phone]" _
& " FROM PatientRecords WHERE member_no ='" & arrMembers(i) & "'"
Set rstMedicine = dbs.OpenRecordset(strGetMemberInfo, dbOpenSnapshot)
Dim intMedicine As Integer
intMedicine = rstMedicine.RecordCount
If intMedicine > 12 Then
intMedicine = 12
End If
Do Until rstMedicine.EOF
For x = 1 To intMedicine
strMedicationField = strMedication & x
strDoctorFNameField = strDoctorFName & x
strDoctorLNameField = strDocotrLName & x
strDoctorPhoneField = strDoctorPhone & x
strSQL = "UPDATE TransformationTable SET " & strMedicationField & " = '" & rstMedicine.Fields("[Medication Name]").Value & "'," & strDoctorFNameField & " = '" & rstMedicine.Fields("[First Name]").Value & "', " & strDoctorLNameField & " = '" & Replace(rstMedicine.Fields("[Last Name]"), "'", "''") & "', " & strDoctorPhoneField & " = '" & rstMedicine.Fields("[doc phone]").Value & "' WHERE member_no ='" & arrMembers(i) & "'"
dbs.Execute strSQL
rstMedicine.MoveNext
Next x
Loop
rstMedicine.Close
Set rstMedicine = Nothing
Next i
在上面的代碼,intMedicine
由第一個記錄集設置,即使rstMedicine.RecordCount確實發生變化也不會改變。
任何幫助表示讚賞
rstMedicine中有多少條記錄?如果它大於12,那麼intMedicine將始終爲12.您說'它不會在下一次調用時重置,但是您希望它重置爲什麼值? – 0liveradam8
你有調試嗎? – June7
它停留在1.它沒有事件設置爲12 –