我有一个按钮,我有一个名为[input norm]的表和两个字段ITEM AND MFG,我已经像这样编写代码了,当我点击按钮时它应该保留msgstr的值,当它调用时函数第二次也应该保留旧的Text32.Value。
例如,在我的情况下,当我调用函数CheckColumnType_TEXT("INPUT NORM", "ITEM")
时,它将显示' ITEM不是TEXT类型' -it在这种情况下是正确的,但是当它调用Call CheckColumnType_TEXT("INPUT NORM", "MFG")
时它会显示' MFG不是TEXT类型'这也是正确的,但问题是,Text32.Value存储最新的值,即MFG不是TEXT类型,但我想要 ITEM不是TEXT类型而 MFG不是TEXT类型保留在Text32.Value字段中。任何帮助将不胜感激
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 :(得分:0)
在处理开始时初始化TextBox:
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"
'...