|
Public coTBuyInvoice As New Collection
Public Sub NewTBuyInvoice()
fm.FilterOn = True
fm.Filter = "Me.InvoiceId='" & mId & "'" ‘过滤
调换一下顺序看看
fm.Filter = "Me.InvoiceId='" & mId & "'" ‘过滤
fm.FilterOn = True
==========
我觉得你的代码效率不高,可能这样要好点:
Public Sub NewTBuyInvoice()
On Error GoTo NewTBuyInvoice_Err
Dim mId As String
mId = InputBox("请输入发票号", "提示")
If mId = "" Then Exit Sub
If Nz(DLookup("InvoiceId", "tbTBuyInvoice", "InvoiceId='" & mId & "'"), "") = mId Then
MsgBox "此发票号已经存在,请重新输入!", vbExclamation, "提示"
Exit Sub
End If
'新建发票
'====================
Dim StrSql As String '不清楚你的字段类型,'UserName'为文本, #BuildDate#为日期
StrSql = "insert into tbTBuyInvoice(InvoiceId,BuildDate,BuildMan) "
StrSql = StrSql & " select '" & mId & "', #" & BuildDate & "#, '" & DLookup("EmployeeId", "tbEmployee", "UserName='" & mUserName & "'") & "'"
CurrentProject.Connection.Execute (StrSql)
'打开新记录编辑
Dim fm As Form
Set fm = New Form_fmTBuyInvoice '打开新窗口
fm.RecordSource = "select * from tbTBuyInvoice where InvoiceId='" & mId & "'"
fm.AllowAdditions = False '表头不可编辑
fm.Caption = "编辑发票" & mId
fm.Visible = True
coTBuyInvoice.Add Item:=fm, Key:=CStr(fm.Hwnd)
Set fm = Nothing
NewTBuyInvoice_Exit:
Exit Sub
NewTBuyInvoice_Err:
MsgBox Err.Description
Resume NewTBuyInvoice_Exit
end sub |
|