Changing the Value of a Record Field

K

Karen K.

I have a form with a command button. I'm trying to make
the button change the value of the "blockuser" field in
the table "tblBlockUser".

Q: Is the code below the easiest way to change the value?
Q: How do I call for the current value?

Dim MyDB As Database
Dim MyRS As Recordset
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecordset("tblBlockuser")

With MyRS
.Edit
If msgResult = vbYes Then
!BlockUser = True
Me.cmdBlock.ForeColor = 255
Me.cmdBlock.FontBold = True
Else
!BlockUser = False
Me.cmdBlock.ForeColor = 0
Me.cmdBlock.FontBold = False
End If
.Update
End With

MyRS.Close
MyDB.Close
 
P

PC Datasheet

You could write more abbreviated code:

With MyRS
.Edit
!BlockUser = Me!MsgResult
IIF(Me!MsgResult, Me.cmdBlock.ForeColor = 255, Me.cmdBlock.ForeColor =
0)
Me.cmdBlock.FontBold = Me!MsgResult
.Update
End With

BTW, your statement, MyDB.Close, should be Set MyDb = Nothing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top