vba程序
Private Sub WaitPeriod_AfterUpdate()
Dim mydata As Database, pmt As Recordset
Set mydata = DBEngine.Workspaces(0).OpenDatabase(DataFile())
If Not IsNull(Me![PaymentMethods]) Then
If Left(Me![PaymentMethods], 5) = "Prom_" Then Exit Sub
End If
Set pmt = Me.RecordsetClone
If Not IsNull(Me![WaitPeriod]) Then
If Me![WaitPeriod] > 0 Then
part2$ = Format$(Nz(Me![WaitPeriod], 0), "000")
Else
part2$ = "000"
End If
If Me![CkType] Then part1$ = "CK"
If Me![CreditCardType] Then part1$ = "CC"
If Me![Artype] Then part1$ = "AR"
If Me![OtherType] Then part1$ = "OT"
If Me![Adjustment] Then part1$ = "AJ"
If Me![RefundType] Then
If part1$ = "CC" Then
part1$ = "CR"
Else
Me![CkType] = False
Me![CreditCardType] = False
Me![Artype] = False
Me![OtherType] = True
Me![Adjustment] = False
part1$ = "RF"
End If
End If
PArt3$ = Format$(Nz(Me![IDnum], 0), "0000")
If Not IsNull(Me![PaymentMethods]) Then
OldMethod$ = Me![PaymentMethods]
If InStr(1, UCase$(Me![PaymentMethods]), "PROM_") <> 1 Then
' make the key
Me![PaymentID] = "R" & part1$ & part2$ & PArt3$
' now find if there is a twin in the promised types
' Save current location
MyLoc$ = Me.Book
MyExpr$ = "Right([PaymentID],4) = '" & Right$(Me![PaymentID], 4) & "'"
pmt.FindFirst MyExpr$
If Not pmt.EOF Then
If Not pmt.nomatch Then
If Left$(pmt![PaymentID], 1) = "R" Then
pmt.FindNext MyExpr$
If Not pmt.EOF Then
If Not pmt.nomatch Then
' change this PaymentID
NewBookMark$ = pmt.Book
Me.Book = NewBookMark$
GoSub SetCloneVal
Me.Book = MyLoc$
Else
DoCmd.GoToRecord , , A_NEWREC
GoSub SetCloneVal
Me.Book = MyLoc$
End If End If
End If
End If
End If
End If
End If
End If
Exit SubSetCloneVal:
Me!PaymentID = "W" & part1$ & part2$ & PArt3$
Me![WaitPeriod] = Val(part2$)
Me![PaymentMethods] = "Prom_" & OldMethod$
Me![CreditCardType] = False
Me![OtherType] = False
Me![CkType] = False
Me![Artype] = False
Me![Adjustment] = False
Select Case part1$
Case "CC"
Me![CreditCardType] = True
Case "CK"
Me![CkType] = True
Case "OT"
Me![OtherType] = True
Case "AR"
Me![Artype] = True
Case "RC"
Me![RefundType] = True
Me![CreditCardType] = True
Case "RF"
Me![RefundType] = True
Me![OtherType] = True
Case "AJ"
Me![Adjustment] = True
End SelectReturn
End Sub
Private Sub WaitPeriod_AfterUpdate()
Dim mydata As Database, pmt As Recordset
Set mydata = DBEngine.Workspaces(0).OpenDatabase(DataFile())
If Not IsNull(Me![PaymentMethods]) Then
If Left(Me![PaymentMethods], 5) = "Prom_" Then Exit Sub
End If
Set pmt = Me.RecordsetClone
If Not IsNull(Me![WaitPeriod]) Then
If Me![WaitPeriod] > 0 Then
part2$ = Format$(Nz(Me![WaitPeriod], 0), "000")
Else
part2$ = "000"
End If
If Me![CkType] Then part1$ = "CK"
If Me![CreditCardType] Then part1$ = "CC"
If Me![Artype] Then part1$ = "AR"
If Me![OtherType] Then part1$ = "OT"
If Me![Adjustment] Then part1$ = "AJ"
If Me![RefundType] Then
If part1$ = "CC" Then
part1$ = "CR"
Else
Me![CkType] = False
Me![CreditCardType] = False
Me![Artype] = False
Me![OtherType] = True
Me![Adjustment] = False
part1$ = "RF"
End If
End If
PArt3$ = Format$(Nz(Me![IDnum], 0), "0000")
If Not IsNull(Me![PaymentMethods]) Then
OldMethod$ = Me![PaymentMethods]
If InStr(1, UCase$(Me![PaymentMethods]), "PROM_") <> 1 Then
' make the key
Me![PaymentID] = "R" & part1$ & part2$ & PArt3$
' now find if there is a twin in the promised types
' Save current location
MyLoc$ = Me.Book
MyExpr$ = "Right([PaymentID],4) = '" & Right$(Me![PaymentID], 4) & "'"
pmt.FindFirst MyExpr$
If Not pmt.EOF Then
If Not pmt.nomatch Then
If Left$(pmt![PaymentID], 1) = "R" Then
pmt.FindNext MyExpr$
If Not pmt.EOF Then
If Not pmt.nomatch Then
' change this PaymentID
NewBookMark$ = pmt.Book
Me.Book = NewBookMark$
GoSub SetCloneVal
Me.Book = MyLoc$
Else
DoCmd.GoToRecord , , A_NEWREC
GoSub SetCloneVal
Me.Book = MyLoc$
End If End If
End If
End If
End If
End If
End If
End If
Exit SubSetCloneVal:
Me!PaymentID = "W" & part1$ & part2$ & PArt3$
Me![WaitPeriod] = Val(part2$)
Me![PaymentMethods] = "Prom_" & OldMethod$
Me![CreditCardType] = False
Me![OtherType] = False
Me![CkType] = False
Me![Artype] = False
Me![Adjustment] = False
Select Case part1$
Case "CC"
Me![CreditCardType] = True
Case "CK"
Me![CkType] = True
Case "OT"
Me![OtherType] = True
Case "AR"
Me![Artype] = True
Case "RC"
Me![RefundType] = True
Me![CreditCardType] = True
Case "RF"
Me![RefundType] = True
Me![OtherType] = True
Case "AJ"
Me![Adjustment] = True
End SelectReturn
End Sub
Private Sub PayMethGrid_AfterEdit(ByVal Row As Long, ByVal Col As Long)
Select Case Col
Case Grid11_Days 这一列相当于WaitPeriod
If Not IsNull(PayMethGrid.TextMatrix(Row, Grid11_PaymentMethod)) Then
If Left(PayMethGrid.TextMatrix(Row, Grid11_PaymentMethod), 5) = "Prom_" Then Exit Sub
End If
If Not IsNull(PayMethGrid.TextMatrix(Row, Grid11_Days)) Then
If PayMethGrid.TextMatrix(Row, Grid11_Days) > 0 Then
Part2 = Format(PayMethGrid.TextMatrix(Row, Grid11_Days), "000")
Else
Part2 = "000"
End If
If PayMethGrid.TextMatrix(Row, Grid11_CkType) Then Part1$ = "CK"
If PayMethGrid.TextMatrix(Row, Grid11_CCType) Then Part1$ = "CC"
If PayMethGrid.TextMatrix(Row, Grid11_ARType) Then Part1$ = "AR"
If PayMethGrid.TextMatrix(Row, Grid11_OtherType) Then Part1$ = "OT"
If PayMethGrid.TextMatrix(Row, Grid11_Adjustment) Then Part1$ = "AJ"
If PayMethGrid.TextMatrix(Row, Grid11_Refund) Then
If Part1 = "CC" Then
Part1 = "CR"
Else
PayMethGrid.TextMatrix(Row, Grid11_CkType) = False
PayMethGrid.TextMatrix(Row, Grid11_CCType) = False
PayMethGrid.TextMatrix(Row, Grid11_ARType) = False
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = True
PayMethGrid.TextMatrix(Row, Grid11_Adjustment) = False
Part1 = "RF"
End If
End If
End If
Part3 = Format(PayMethGrid.TextMatrix(Row, Grid11_IDNum), "0000")
If Not IsNull(PayMethGrid.TextMatrix(Row, Grid11_PaymentMethod)) Then
OldMethod = PayMethGrid.TextMatrix(Row, Grid11_PaymentMethod)
End If
If InStr(1, UCase(PayMethGrid.TextMatrix(Row, Grid11_PaymentMethod)), "PROM_") <> 1 Then
PayMethGrid.TextMatrix(Row, Grid11_ID) = "R" & Part1 & Part2 & Part3
Else
strFind = "Right(PayMethGrid.TextMatrix(Row, Grid11_ID),4) = '" & Right(PayMethGrid.TextMatrix(Row, Grid11_ID), 4) & "'"
' rs.Filter (strFind)
PayMethLoc = PayMethRs.BookMark
PayMethRs.Find (strFind)
If Not PayMethRs.EOF Then
If Not PayMethRs.BOF Then
If Left(PayMethGrid.TextMatrix(PayMethGrid.RowSel, Grid11_ID), 1) = "R" Then
PayMethRs.Find (strFind)
If Not PayMethRs.EOF Then
If Not PayMethRs.BOF Then
NewBookMark = PayMethRs.BookMark
BookMark = NewBookMark
PayMethGrid.TextMatrix(Row, Grid11_ID) = "W" & Part1 & Part2 & Part3
PayMethGrid.TextMatrix(Row, Grid11_Days) = Val(Part2)
PayMethGrid.TextMatrix(Row, Grid11_CCType) = "Prom_" & OldMethod
PayMethGrid.TextMatrix(Row, Grid11_CCType) = False
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = False
PayMethGrid.TextMatrix(Row, Grid11_CkType) = False
PayMethGrid.TextMatrix(Row, Grid11_ARType) = False
PayMethGrid.TextMatrix(Row, Grid11_Adjustment) = False
Select Case Part1
Case "CC"
PayMethGrid.TextMatrix(Row, Grid11_CCType) = True
Case "CK"
PayMethGrid.TextMatrix(Row, Grid11_CkType) = True
Case "OT"
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = True
Case "AR"
PayMethGrid.TextMatrix(Row, Grid11_ARType) = True
Case "RC"
PayMethGrid.TextMatrix(Row, Grid11_Refund) = True
PayMethGrid.TextMatrix(Row, Grid11_CCType) = True
Case "RF"
PayMethGrid.TextMatrix(Row, Grid11_Refund) = True
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = True
Case "AJ"
PayMethGrid.TextMatrix(Row, Grid11_Adjustment) = True
End Select
BookMark = PayMethLoc
Else
' DoCmd.GoToRecord , , A_NEWREC
PayMethGrid.TextMatrix(Row, Grid11_ID) = "W" & Part1 & Part2 & Part3
PayMethGrid.TextMatrix(Row, Grid11_Days) = Val(Part2)
PayMethGrid.TextMatrix(Row, Grid11_CCType) = "Prom_" & OldMethod
PayMethGrid.TextMatrix(Row, Grid11_CCType) = False
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = False
PayMethGrid.TextMatrix(Row, Grid11_CkType) = False
PayMethGrid.TextMatrix(Row, Grid11_ARType) = False
PayMethGrid.TextMatrix(Row, Grid11_Adjustment) = False
Select Case Part1
Case "CC"
PayMethGrid.TextMatrix(Row, Grid11_CCType) = True
Case "CK"
PayMethGrid.TextMatrix(Row, Grid11_CkType) = True
Case "OT"
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = True
Case "AR"
PayMethGrid.TextMatrix(Row, Grid11_ARType) = True
Case "RC"
PayMethGrid.TextMatrix(Row, Grid11_Refund) = True
PayMethGrid.TextMatrix(Row, Grid11_CCType) = True
Case "RF"
PayMethGrid.TextMatrix(Row, Grid11_Refund) = True
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = True
Case "AJ"
PayMethGrid.TextMatrix(Row, Grid11_Adjustment) = True
End Select
BookMark = PayMethLoc
End If
End If
End If
End If
End If
End If
Case Grid11_CkType
If PayMethGrid.TextMatrix(Row, Grid11_CkType) Then
PayMethGrid.TextMatrix(Row, Grid11_CCType) = False
PayMethGrid.TextMatrix(Row, Grid11_ARType) = False
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = False
PayMethGrid.TextMatrix(Row, Grid11_Adjustment) = False
Else
PayMethGrid.TextMatrix(Row, Grid11_OtherType) = True
End If
If IsNull(PayMethGrid.TextMatrix(Row, Grid11_Days)) Then PayMethGrid.TextMatrix(Row, Grid11_Days) = 0
Call PayMethGrid_AfterEdit(Row, Grid11_Days)
Case Grid11_CCType
End Select
End Sub
关键是现在我没有实现vba中的
MyLoc$ = Me.Book
MyExpr$ = "Right([PaymentID],4) = '" & Right$(Me![PaymentID], 4) & "'"
pmt.FindFirst MyExpr$
就是书签的一些用法,这个怎么修改?