我正在盡我所能來劃分我的所有代碼,因此它是完全靈活的。然而,當我嘗試運行代碼時,我遇到了一個問題。它就像這樣進入正在生產:無效的外部程序。與變量和querys鬼混
在我的程序的頂部我有一個看起來像這幾個變量:
Public Sub varHolder() 'this
Dim monday As String
Dim tuesday As String
Dim wednesday As String
Dim thursday As String
Dim friday As String
Dim day As String
Dim stepQuery As String
Dim i As Integer
Dim db As DAO.Database
Dim rsStepCalendar As DAO.Recordset
Set db = CurrentDb
Set rsStepCalendar = stepQuery
end sub
我的程序的下一個部分,我開始填補這些變量與值。
Private Sub btnNewContact_Click()
call varHolder 'this
Dim header As Integer
header = Forms!frmContactsEdit!txtHeader.Value
If chkActive = True Then
stepQuery = db.OpenRecordset("Select * from tblStepCalendar " & _
"Where (HeaderID = '" & header & "') " & _
"AND (Cancel = False)" & _
"AND (Active = True)", dbOpenDynaset)
monday = chkMonA.Value
tuesday = chkTuesA.Value
wednesday = chkWedA.Value
thursday = chkThursA.Value
friday = chkFriA.Value
day = lstActive.Selected(i)
Call stepUpdater
End If
If chkRetiree = True Then
stepQuery = db.OpenRecordset("Select * from tblStepCalendar " & _
"Where (HeaderID = '" & header & "') " & _
"AND (Cancel = False)" & _
"AND (Retiree = True)", dbOpenDynaset)
monday = chkMonB.Value
tuesday = chkTuesB.Value
wednesday = chkWedB.Value
thursday = chkThursB.Value
friday = chkFriB.Value
day = lstRetiree.Selected(i)
Call stepUpdater
End If
If chkCobra = True Then
stepQuery = db.OpenRecordset("Select * from tblStepCalendar " & _
"Where (HeaderID = '" & header & "') " & _
"AND (Cancel = False)" & _
"AND (Cobra = True)", dbOpenDynaset)
monday = chkMonC.Value
tuesday = chkTuesC.Value
wednesday = chkWedC.Value
thursday = chkThursC.Value
friday = chkFriC.Value
day = lstCobra.Selected(i)
Call stepUpdater
End If
End Sub
我用適當的變量執行代碼後。
Public Sub stepUpdater()
call varHolder 'this
If rsStepCalendar.EOF Then
RstRecSet.Add
rsStepCalendar("Monday").Value = monday
rsStepCalendar("Tuesday").Value = tuesday
rsStepCalendar("Wednesday").Value = wednesday
rsStepCalendar("Thursday").Value = thursday
rsStepCalendar("Friday").Value = friday
RstRecSet.Update
For i = 0 To 32
If day <> rsStepCalendar(i).Value Then
RstRecSet.Add
rsStepCalendar(i).Value = rsStepCalendar(i).Value
RstRecSet.Update
End If
Next
MsgBox ("Record Added")
Else
If chkMonA <> rsStepCalendar("Monday").Value Then
RstRecSet.Edit
rsStepCalendar("Monday").Value = monday
RstRecSet.Update
End If
If chkTuesA <> rsStepCalendar("Tuesday").Value Then
RstRecSet.Edit
rsStepCalendar("Tuesday").Value = tuesday
RstRecSet.Update
End If
If chkWedA <> rsStepCalendar("Wednesday").Value Then
RstRecSet.Edit
rsStepCalendar("Wednesday").Value = wednesday
RstRecSet.Update
End If
If chkThursA <> rsStepCalendar("Thursday").Value Then
RstRecSet.Edit
rsStepCalendar("Thursday").Value = thursday
RstRecSet.Update
End If
If chkFriA <> rsStepCalendar("Friday").Value Then
RstRecSet.Edit
rsStepCalendar("Friday").Value = friday
RstRecSet.Update
End If
For i = 0 To 32
If day <> rsStepCalendar(i).Value Then
RstRecSet.Edit
rsStepCalendar(i).Value = rsStepCalendar(i).Value
RstRecSet.Update
End If
Next
End If
End Sub
我的問題是我在做什麼我不假設?這個錯誤源於我試圖使用所有這些功能嗎?與我得到的錯誤的問題是我可以調試,所以我很無知,我做錯了什麼。
編輯:
Dim db As DAO.Database
Dim rsStepCalendar As DAO.Recordset
Call Initialize
Sub Initialize()
Set db = CurrentDb
Set rsStepCalendar = stepQuery
End Sub
'請問錯誤stem' - **什麼錯誤** – cybermonkey 2015-02-05 17:42:27