设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
楼主: yori2007
打印 上一主题 下一主题

[模块/函数] 帮忙看看这段新建记录代码有没有问题

[复制链接]
11#
发表于 2012-6-12 20:57:43 | 只看该作者
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
12#
发表于 2012-6-12 21:23:11 | 只看该作者
楼主可以换一种思路
新增窗体时,清空所有数据,保存时才检测数据的完整性,唯一性
13#
发表于 2012-6-12 22:48:58 | 只看该作者
我觉得你的代码效率不高,可能这样要好点:
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
14#
发表于 2012-6-12 22:49:36 | 只看该作者
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
15#
发表于 2012-6-12 22:49:52 | 只看该作者
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
16#
 楼主| 发表于 2012-6-13 09:10:21 | 只看该作者
我现在纠结的是,为什么C可以,而V不可以啊
17#
 楼主| 发表于 2012-6-13 09:28:20 | 只看该作者
晕,到现在才看到审核后的帖子,谢谢,我试试啊
18#
 楼主| 发表于 2012-6-13 11:50:46 | 只看该作者
好像还是有错,我还是纠结于       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
这段代码有没有问题
19#
 楼主| 发表于 2012-6-15 14:25:12 | 只看该作者
还没搞定,有没有人再帮我看看啊
20#
 楼主| 发表于 2012-6-15 20:32:02 | 只看该作者
求关注
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-17 16:47 , Processed in 0.090224 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表