
Photo by
reo_for_irnmn
AccessVBAで、テーブルに新規レコードとしてテキストボックスの値を追加する
Dim code As String
Dim productName As String
Dim price As String
If IsNull(txtBox_製品コード) Then
MsgBox "コードが空白です"
End
Else
code = txtBox_製品コード
End If
If IsNull(txtBox_部品名) Then
buhinmei = ""
Else
buhinmei = txtBox_製品名
End If
If IsNull(txtBox_単価) Then
MsgBox "単価が空白です"
End
Else
price = txtBox_単価
End If
Dim RstCo As ADODB.Connection
Dim Rst As New ADODB.Recordset
Set RstCo = Application.CurrentProject.Connection
Rst.Open "T_製品マスタ", RstCo, adOpenKeyset, adLockOptimistic
With Rst
.AddNew
.Fields("製品コード") = code
.Fields("製品名") = productName
.Fields("単価") = price
.Update
End With
Rst.Close
Set Rst = Nothing
RstCo.Close
Set RstCo = Nothing
MsgBox "データを追加しました"
Me!txtBox_製品コード = ""
Me!txtBox_製品名 = ""
Me!txtBox_単価 = ""
Me.Requery