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 –