Exit from operation

sohailcdc

Registered User.
Local time
Today, 01:54
Joined
Sep 25, 2012
Messages
55
Hi there
I am trying to learn the Access need help from the guru of Access
Below are the code, which I am trying to use to update the field in a record, What I am trying to achieve, is once I press/click the update button, cursor needs to move to next desire field which is "txteditcid", but after pressing the update button, I am getting following error (however, field is updating in table)

Run-time error '2110':
Microsoft Access can't move the focus to the control txteditcid
Apparently, look like looping issue - but not sure, can someone help-me
Thanks for your valuable comments

Code
Private Sub Butupdatecustemail_Click()
Dim dbs As DAO.Database, update1 As String, rcount As Integer
Set dbs = CurrentDb
update1 = "UPDATE CustomerProfile set custemail='" & Me.txteditcustemail & "'" & "WHERE cid='" & Me.txteditcid & "'"

dbs.Execute update1, dbFailOnError
rcount = dbs.RecordsAffected
If rcount > 0 Then
MsgBox "Field record updated", vbInformation, "Confirmation"
Listeditcustomerprofile.Requery
Me.txteditcustemail.Enabled = False
Cancel = True
txteditcid.SetFocus
Exit Sub

End If

End Sub
 
Are you sure that the control "txteditcid" enabled is true?
For what use do you have the code line "Cancel = True"?
Why are you sometime using "Me" operator and other time not, be consistent!
 
Are you sure that the control "txteditcid" enabled is true?
For what use do you have the code line "Cancel = True"?
Why are you sometime using "Me" operator and other time not, be consistent!

Strange that the 'Cancel = True' does not produce an error in a function which does not have Cancel as a parameter.

Best,
Jiri
 
Strange that the 'Cancel = True' does not produce an error in a function which does not have Cancel as a parameter.
No it isn't, "Cancel" is just a variable name like "MyVariableName", "YourVarialbleName". If you not have set the option "Option Explicit" in the module level, you can use undeclared variables.
 
i struggle to see how this block gets executed at all. what does the first line achieve? what is the sub trying to achieve?


Code:
rcount = dbs.RecordsAffected
If rcount > 0 Then
     MsgBox "Field record updated", vbInformation, "Confirmation"
     Listeditcustomerprofile.Requery
     Me.txteditcustemail.Enabled = False
     Cancel = True
     txteditcid.SetFocus
Exit Sub
 

Users who are viewing this thread

Back
Top Bottom