我被困住了。我有一个表格,其中包含使用公司名称和Emp Nbr,雇用日期和职务代码的字段。喜欢([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中的值。
然后添加Field ...就像...... DoCmd.RunSQL“ALTER TABLE [员工清单表] ADD COLUMN [亚马逊企业] TEXT(25);”
更像...... DoCmd.RunSQL“ALTER TABLE [Employee Inventory Table] ADD COLUMN”[“& strNewCompanyName&”Emp Nbr]“TEXT(25);”
我希望这是有道理的......提前谢谢!
答案 0 :(得分:0)
还有另一种语法可以引用表单中的字段,它可以满足您的需求。尝试:
Me(variableName).Value
应该这样做。