Ms access 使用VBA在Access中运行SAS

Ms access 使用VBA在Access中运行SAS,ms-access,vba,sas,Ms Access,Vba,Sas,读完这篇文章: 我决定尝试使用Access运行SAS程序,但VBA遇到了一些问题 这是我的密码: Private Sub Command_Click() Dim olesas as Object Dim Data_ID as String 'note this is the name of a txtbox in my form dd_id=Data_ID.Value 'here is where my error is Set olesas=CreateObject("SAS.Applicat

读完这篇文章:

我决定尝试使用Access运行SAS程序,但VBA遇到了一些问题

这是我的密码:

Private Sub Command_Click()
Dim olesas as Object
Dim Data_ID as String 'note this is the name of a txtbox in my form
dd_id=Data_ID.Value 'here is where my error is
Set olesas=CreateObject("SAS.Application")
olesas.Submit (" %let DD_ID=" & dd_id & "; %inc 'SASMACRO'") 'didn't feel like typing whole inc statement here
olesas.Visable=True
olesas.Quit
Set olesas=Nothing
End Sub
当我试图将表单中的参数设置为VBA中的变量,然后将其转换为SAS中的宏变量时,出现错误。有什么想法吗

Dim Data_ID as String 'note this is the name of a txtbox in my form
dd_id=Data_ID.Value 'here is where my error is
通过将数据_ID暗显为字符串,该字符串没有对表单上的txtbox的引用。您在这里所做的是创建一个名为data_ID的变量,该变量没有赋值,并尝试使用一个名为dd_ID的未声明变量

dim dd_id as String
dd_id = me.Data_ID.Value ' assuming data_id is the name of your txtbox
如果你的txtbox和你的按钮在同一个表单上,那么你可以使用我。引用该窗体的控件。如果txtbox位于另一个表单上,则需要通过表单显式引用!你的名字!数据标识值

还有一件事,恰当地命名控件始终是一种良好的做法,因此,对于txtbox名称,控件txtDataID和按钮btnNameHere等,从长远来看会使事情变得更容易


HTH

dd_id=Data_id.Value未变暗-是否设置了显式选项?这是一条VBA线,所以它与SAS无关。您也没有正确引用您的txtbox-我认为您需要将dd_id设置为字符串,而不是数据_id,因为您希望它成为您的文本框。你应该看看如何引用文本框-我不记得确切的访问对象模型,但它类似于Application.textboxs.TextboxData_ID或类似的东西。现在我读了这篇文章,他们就是这样做的。。。我是一个优秀的VBA人,但对我来说那将是非常。。。古怪的使字符串变暗并神奇地从中获取文本框值。谢谢@Joe。我将进一步调查此事。