我目前有一个Access数据库,员工每月手动输入记录。相反,我想上传一个Excel电子表格并填充数据库中的所有列。问题是某些列的VBA代码会进行一些计算,当我上传电子表格时,只有当您键入一个计算的值时才会进行计算。
有解决方法吗?
Option Explicit
Option Compare Database
Dim strStopReading As String
Dim datDate As Date
Private Sub AdjWater_BeforeUpdate(Cancel As Integer)
Call UpdateCharges
End Sub
Private Sub Form_AfterUpdate()
varLastReading = StopReading
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.StartReading = varLastReading
If Me.Parent.BillingMethod = 3 Then
If IsNull(Me.Date) Then
AmountCharged = curWater
Else
AmountCharged = GetRate(Me.Date, Me.Parent.strWaterCode)
End If
End If
End Sub
Private Sub Gallons_Change()
Call UpdateCharges
End Sub
Private Sub StartReading_Change()
If Not IsNumeric(StartReading.Text) Then Exit Sub
If Not IsNull(StopReading) Then
Gallons = StopReading - StartReading.Text
UpdateCharges
End If
End Sub
Private Sub StopReading_Change()
If Not IsNumeric(StopReading.Text) Then Exit Sub
If Not IsNull(StartReading) Then
Gallons = StopReading.Text - StartReading
UpdateCharges
End If
End Sub
Public Sub UpdateCharges()
Dim blnChkNum As String
Dim curWaterRate As Currency
Dim curSewerRate As Currency
Dim curMinRate As Currency
'if date is null then use current rate
If IsNull(Me.Date) Then
curWaterRate = curWater
curSewerRate = curSewer
curMinRate = curMinChg
Else
curWaterRate = GetRate(Me.Date, Me.Parent.strWaterCode)
curSewerRate = GetRate(Me.Date, Me.Parent.strSewerCode)
curMinRate = GetRate(Me.Date, Me.Parent.strMinChgCode)
End If
If Me.ActiveControl.Properties("Name") = "txtGallonsToInvoice" Then
'txtGallonsToInvoice is active
blnChkNum = IsNumeric(txtGallonsToInvoice.Text) 'check the text - it may
differ from saved value
If blnChkNum Then
'update amount charged for water
If Me.Parent.BillingMethod = 2 Then AmountCharged =
txtGallonsToInvoice.Text / 1000 * curWaterRate
If Me.Parent.BillingMethod = 3 Then AmountCharged = curWaterRate
'update sewer
If blnSewer = True Then
SewerChg = txtGallonsToInvoice.Text / 1000 * curSewerRate
Else
SewerChg = 0
End If
End If
Else 'Another control has the focus
blnChkNum = IsNumeric(txtGallonsToInvoice) 'check the value - you
can't access the text without the focus
If blnChkNum Then
'update amount charged for water
If Me.Parent.BillingMethod = 2 Then AmountCharged =
txtGallonsToInvoice / 1000 * curWaterRate
If Me.Parent.BillingMethod = 3 Then AmountCharged = curWaterRate
'update sewer
If blnSewer = True Then
SewerChg = txtGallonsToInvoice / 1000 * curSewerRate
Else
SewerChg = 0
End If
End If
End If
If strRateGroup <> "TB" Then 'skip min charge for Houston Ship Repair
If AmountCharged < curMinRate Then
AmountCharged = curMinRate
Me.Min_Water_Chg = True
Else
Me.Min_Water_Chg = False
End If
Else
Me.Min_Water_Chg = False
End If
End Sub
Private Sub txtGallonsToInvoice_Change()
UpdateCharges
End Sub