Вы находитесь на странице: 1из 1

How to update records in an Excel database with a user-form.

When we create a
database and make data entries, we are bound to make mistakes. Once we discover the
errors or somebody points out to them, we need to take corrective action and update
the records.

Here�s the VBA code:

Dim currentrow As Long �declaration of the global variable right at the top

Private Sub UserForm_Initialize()


currentrow = 2
TextBox1 = Cells(currentrow, 1)
TextBox2 = Cells(currentrow, 2)
TextBox3 = Cells(currentrow, 3)

End Sub

Private Sub cmdUpdate_Click()


answer = MsgBox(�Are you sure you want to update the record?�, vbYesNo +
vbQuestion, �Update Record�)
If answer = vbYes Then
Cells(currentrow, 1) = TextBox1.Text
Cells(currentrow, 2) = TextBox2.Text
Cells(currentrow, 3) = TextBox3.Value
End If

End Sub

Вам также может понравиться