2017-09-14 51 views
0

我有一個按鈕,我有一個名爲[input norm]的表和兩個字段ITEM AND MFG,並且我已經像這樣寫了代碼,當我單擊在按鈕上它應該保留msgstr的值,當它第二次調用函數時,舊的Text32.Value也應該被保留。 例如,在我調用函數CheckColumnType_TEXT("INPUT NORM", "ITEM")時,它會顯示'ITEM不是TEXT類型' - 在這種情況下它是正確的,但是當它調用Call CheckColumnType_TEXT("INPUT NORM", "MFG")時,它將顯示'MFG不是TEXT類型',這是正確的嗯,但問題是,Text32.Value存儲最新值即MFG不是TEXT類型,但我希望兩者ITEM不是TEXT類型MFG不是TEXT類型將保留在我的Text32.Value字段。任何幫助將不勝感激 enter image description here多次調用函數後需要在文本字段中保留值

Private Sub Command0_Click() 
    Dim db As DAO.Database 
    Set db = CurrentDb() 
    Dim str As String 
    Call CheckColumnType_TEXT("INPUT NORM", "ITEM") 
    Call CheckColumnType_TEXT("INPUT NORM", "MFG") 
    End Sub 

Function CheckColumnType_TEXT(TblName As String, ColName As String) 
Dim db As DAO.Database 
Set db = CurrentDb() 
Dim tbl_nks As DAO.TableDef 
Set tbl_nks = db.TableDefs("[INPUT NORM]") 
If ifFieldExists(ColName, "[INPUT NORM]") Then 
If (tbl_nks.Fields(ColName).Type = dbText) = False Then 
Dim msgstr As String 
msgstr = msgstr & ColName & " is not TEXT Type" + vbCrLf 
'Return msgstr 
Text32.Value = msgstr 
Text32.ForeColor = vbBlue 
'status.Value = "" 
'Exit Function 
Else 
End If 
Else 
MsgBox ColName & " field is not available", vbCritical 
'status.Value = "" 
End If 
End Function 

    Public Function ifFieldExists(FLDNAME As String, TableName As String) As Boolean 
Dim rs As Recordset, db As DAO.Database 'Sub DAO Vars 
On Error GoTo fs 
Set db = CurrentDb() 
Set rs = db.OpenRecordset("Select " & FLDNAME & " from " & TableName & ";") 
ifFieldExists = True 
rs.Close 
db.Close 
Exit Function 
fs: 
Set rs = Nothing 
db.Close 
Set db = Nothing 
ifFieldExists = False 
Exit Function 
End Function 

回答

0

初始化的文本框,在你處理的開始:

Private Sub Command0_Click() 
    Dim db As DAO.Database 
    Set db = CurrentDb() 
    Dim str As String 
    Text32.Value = "" 
    Call CheckColumnType_TEXT("INPUT NORM", "ITEM") 
    Call CheckColumnType_TEXT("INPUT NORM", "MFG") 
End Sub 

,然後每次更新您檢查一列:

Function CheckColumnType_TEXT(TblName As String, ColName As String) 
    '... 
    '... 
    'Dim msgstr As String 
    If Text32.Value <> "" Then 
     Text32.Value = Text32.Value & vbCrLf 
    End If 
    Text32.Value = Text32.Value & ColName & " is not TEXT Type" 
    '... 
相關問題