【问题标题】:Show Message in text box when program ends successfuly or not程序是否成功结束时在文本框中显示消息
【发布时间】:2021-04-27 01:06:20
【问题描述】:

我有下面的代码,当它运行更新 14 个表时,想知道如何使用下面模板中的文本框显示一条消息,显示潜艇是否成功结束。

[Private Sub Command0_Click()

   'Sub 1
    A_Forecast
    
    'Text box showing the msg OK or failed
    A_ForecastTxt "OK" or "Not"

   'Sub 2
    B_Forecast
    
    'Text box showing the msg OK or failed
    B_ForecastTxt "OK" or "Not"

   
End Sub][1]

【问题讨论】:

    标签: vba ms-access-2013


    【解决方案1】:

    把 subs 变成 functions 因为它们可以返回一个值:

    Private Sub Command0_Click()
    
        Dim Success As Boolean
    
        ' Function 1
        Success = A_Forecast
        
        ' Text box showing the msg OK or failed
        MsgBox IIf(Success, "OK", "Failed")
    
        ' Function 2
        Success = B_Forecast
        
        ' Text box showing the msg OK or failed
        MsgBox IIf(Success, "OK", "Failed")
       
    End Sub
    

    例子:

    Public Function A_Forecast() As Currency
    
        Dim Result As Currency
        Dim Something As Boolean
    
        ' Your code:
        Something = True ' or False
    
        If Something = True Then
            Result = 100
        Else
            Result = 200
        End If
    
        A_Forecast = Result
    
    End Function
    

    【讨论】:

    • 谢谢@Gustav,这是个好主意。但是不确定如何将潜艇转换为函数。已尝试您的代码,但不断收到错误消息:预期函数或变量。
    • 我添加了一个基本示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多