Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access VBA访问DMAX发票编号标准_Ms Access_Vba - Fatal编程技术网

Ms access VBA访问DMAX发票编号标准

Ms access VBA访问DMAX发票编号标准,ms-access,vba,Ms Access,Vba,我试图通过使用DMAX函数来添加一个发票号,用下一个连续的发票号填充一个文本框。根据在组合框Me.cmb\u CustomerType.Value中选择的地产代理名称,发票编号(调查发票编号、调查tbl)将以不同的数字开头,例如Elmhurst将以08开头,Bridgfords将以05开头,Harrington durham将以04开头。 我尝试过使用各种论坛上的select语句、left、dmax、dlookup,但都无法使用,我对此束手无策 If cmb_CustomerType.Value

我试图通过使用DMAX函数来添加一个发票号,用下一个连续的发票号填充一个文本框。根据在组合框Me.cmb\u CustomerType.Value中选择的地产代理名称,发票编号(调查发票编号、调查tbl)将以不同的数字开头,例如Elmhurst将以08开头,Bridgfords将以05开头,Harrington durham将以04开头。 我尝试过使用各种论坛上的select语句、left、dmax、dlookup,但都无法使用,我对此束手无策

If cmb_CustomerType.Value = "Elmhurst" Then
Me.txt_InvoiceNumber.Value = DMax("Survey_InvoiceNumber", "Survey_tbl", "08") + 1
End If

If cmb_CustomerType.Value = "Bridgfords" Then
    Me.txt_InvoiceNumber = Nz(DMax("Survey_InvoiceNumber", "Survey_tbl", "05") + 1)
End If

If cmb_CustomerType.Value = "Harringtons Durham" Then
    Me.txt_InvoiceNumber = Nz(DMax("Survey_InvoiceNumber", "Survey_tbl", "04") + 1)
End If
对于所有的房地产代理,它只返回了“8884”,因为这是该栏中的最高数字

结果应该是:埃尔姆赫斯特-08884,哈林顿-达勒姆-04048

bridgfords当前没有值,因此应该从05000开始

提前感谢:)

试试这个骨架:

Me.txt_InvoiceNumber.Value = "08" & Right(Format(Val(Nz(DMax("Survey_InvoiceNumber", "Survey_tbl", "Survey_InvoiceNumber Like '08*'")) + 1), "00000"), 3)

首先,您的Survey_InvoiceNumber“列是字符串还是长字符串?如果您真的想要前导零(08..05..04..),最好创建一个字符串,但是如果您的dmax返回8884(无前导零),它看起来像一个长字符串。那么,您是否有一列存储客户类型,或者您是否仅依靠发票号码的第一位数字来确定客户类型(坏主意)?@Thomas G,我有一个存储在“Customer_tbl”中的“Customer_Type”属性。我将“Survey_InvoiceNumber”列设置为短文本,以允许数字以0开头,但它似乎对表单没有任何影响