【发布时间】:2018-04-01 14:24:17
【问题描述】:
我被困住了。我有一个表格,其中包含使用公司名称和员工编号、雇用日期和工作代码的字段。喜欢([Amazon Emp Nbr]、[Amazon Hire Date]、Amazon Job Code])。我从已知领域开始,我已经让 Len 工作,但是当我尝试使用变量时,我碰壁了。我在表单的 RecordSource 中使用查询来提取登录用户的所有字段。我可以逐步浏览所有字段,但我知道我要查找的字段。必须有更好的方法。
所以这些工作。
MsgBox (Len(Me.PID.Name))
MsgBox (Len(Me.[First Name].Name))
MsgBox (Len(Me.[Last Name].Name))
但我需要使用一个变量...让我试着解释一下。
strAnswer = MsgBox("Do You Want To Enter A New Company Name? ", vbYesNo, "Do You Want To Enter A New Company Name?")
If strAnswer = "7" Then
MsgBox ("You Clicked NO. Please Reenter!") 'Reenter What?
GoTo EndSection
End If
If strAnswer = "6" Then
MsgBox ("You Clicked YES. Please enter your Information!") 'Enter New User Information!
'This starts the section to enter a new employee Information.
strNewCompanyName = UCase(InputBox("Please Enter the New Company Name", "Enter the New Compay Name", "?"))
If (strNewCompanyName = "") Then
MsgBox ("You Pressed Cancel")
Forms!StartUp.SetFocus
DoCmd.Maximize
GoTo EndSection
End If
If (strNewCompanyName = "?") Then
MsgBox ("You Forgot To Enter A NEW Company Name")
Forms!StartUp.SetFocus
DoCmd.Maximize
End If
End If
VarTest = ([Amazon Emp Nbr].Value) 'This works! Returns Value!
'These don't
VarTest = "[" & strNewCompanyName & " Emp Nbr]"
VarTest = "Me![" & strNewCompanyName & " Emp Nbr]"
VarTest = Eval("[" & strNewCompanyName & " Emp Nbr]")
VarTest = Eval("[" & strNewCompanyName & " Emp Nbr]").Value
VarTest = [ & strNewCompanyName & _Emp_Nbr]
VarTest = "[" & strNewCompanyName & " Emp Nbr].Value"
我想使用 Len 但甚至无法让它返回字段中的值。
然后添加 Field ... Like ... DoCmd.RunSQL "ALTER TABLE [Employee Inventory Table] ADD COLUMN [Amazon Enterprises] TEXT (25);"
更像... DoCmd.RunSQL "ALTER TABLE [Employee Inventory Table] ADD COLUMN "[" & strNewCompanyName & " Emp Nbr]" TEXT (25);"
我希望这是有道理的......提前谢谢你!
【问题讨论】:
-
你可以在 vbGet 中使用 CallByName 吗?
-
谢谢!我不熟悉 CallByName。我会试着查一下。
-
不确定是否合适
标签: vba variables ms-access field