在vba中设置文本框错误的默认值:#Name?,MS访问权限

问题描述 投票:0回答:1

我尝试在VBA,MS Access的文本框中设置默认值。但是它的节目“ #Name?”在文本框中。价值有3部分1. DocTypeShortName:文档类型名称;下午2. Y:年份; 203. DocumentNum:当年的Document数量; 005我想要的结果是PM20005。

Dim Y As Long
Dim DocumentNum As String
Dim DocTypeShortName  As String
        rsfilter = SQL..
    DocumentNum = Format(Right(rsFilter!DocumentNumber, 3) + 1, "000")
    Y = Format(Date, "yy")
    DocTypeShortName = DLookup("Documentshortname", "tblDocumenttype", "documenttypeID = " & 1)

    Forms!frmplanmonth!DocumentNumber.DefaultValue = Y & DocumentNum <-----1. Its show only "20001"
    Forms!frmplanmonth!DocumentNumber.DefaultValue = DocTypeShortName & Y & DocumentNum <-----2. Not ok, show "#Name?"
    Forms!frmplanmonth!DocumentNumber.DefaultValue = "'PM'" <-----3. I try to hard code but its show only "PM"
    Forms!frmplanmonth!DocumentNumber.DefaultValue = "'PM'" & Y & DocumentNum <-----4. Not ok, show "#Name?"

为什么当我仅使用年份和文件编号时,它会起作用。但是,当我尝试添加docTypeShortName时出错。

我做错了什么?请帮忙。谢谢

access-vba
1个回答
0
投票

尝试使用带引号的字符串:

Forms!frmplanmonth!DocumentNumber.DefaultValue = "'" & DocTypeShortName & Y & DocumentNum & "'"
© www.soinside.com 2019 - 2024. All rights reserved.