使用VBA在Access中运行SAS

时间:2015-04-17 17:10:35

标签: vba ms-access access-vba sas

阅读本文后:http://www2.sas.com/proceedings/sugi30/044-30.pdf

我决定尝试使用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中的宏变量。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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

将data_ID调暗为String,它没有引用表单上的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在另一个表单上,则需要显式引用Forms!yourFormName!Data_ID.Value

另外一件事是对控件进行适当命名总是很好的做法,因此对于你的txtbox名称,控件txtDataID和你的按钮btnNameHere等 - 从长远来看会让事情变得更容易。

HTH