我需要从windows命令行调用自动应用程序。这个应用程序启动,进行一些数据库操作并自动退出。 接下来我需要处理Access的返回值。我尝试了在Google上找到的所有内容,但Access每次都返回0。我需要返回1或其他东西告诉cmd数据库中存在错误。
这里是VBA中的一些代码(应用程序启动时访问调用表单):
Private Sub Form_Load()
Dim xSQL As String
Dim xRS As DAO.Recordset
xSQL = "select * from table1"
Set xRS = CurrentDb.OpenRecordset(xSQL, dbOpenDynaset)
xRS.MoveLast: xRS.MoveFirst
DoEvents
If xRS!field1 = "" Or IsNull(xRS!field1) Then
' HERE I WANT TO RETURN 1 OR ANY TRUE VALUE = ERROR
Application.Quit acQuitSaveAll
End If
' HERE I RETURN 0 = SUCCESS
Application.Quit acQuitSaveAll
End Sub
有些想法怎么做?
答案 0 :(得分:0)
我认为您最好的解决方案是设置一个具有所需返回值的环境变量。
来自您的VBA代码:
Private Declare Function SetEnvironmentVariable Lib "kernel32" _
Alias "SetEnvironmentVariableA" _
(ByVal lpName As String, _
ByVal lpValue As String) As Long
Private Sub Form_Load()
Dim xSQL As String
Dim xRS As DAO.Recordset
xSQL = "select * from table1"
Set xRS = CurrentDb.OpenRecordset(xSQL, dbOpenDynaset)
xRS.MoveLast: xRS.MoveFirst
DoEvents
If xRS!field1 = "" Or IsNull(xRS!field1) Then
SetEnvironmentVariable "ACCESSEXITCODE", "1"
Application.Quit acQuitSaveAll
End If
SetEnvironmentVariable "ACCESSEXITCODE", "0"
Application.Quit acQuitSaveAll
End Sub
从de命令行:
IF %ACCESSEXITCODE%==1 GOTO HandleError