קוד VBA מתעתע

קוד VBA מתעתע

כתבתי קוד קצר שמתריע אם שם שמוכנס לטופס כבר נמצא ברשומות, ומאפשר לשמור בכל זאת או לבטל. הקוד עובד, אבל כשהעתקתי אותו למסד אקסס אחר (עם נתונים מעודכנים) הוא מוציא הודעת שגיאה. מדוע? מסד האקסס יושב כולו על השרת (נובל) בשני המקרים. להלן הקוד: Private Sub FirstName_BeforeUpdate(Cancel As Integer) Dim recqry As Recordset Dim strMessage As String Dim intOptions As Integer Dim bytChoice As Byte Dim strSQL As String Dim strFirstName As String Dim strFamilyName As String strFirstName = Me.FirstName strFamilyName = Me.FamilyName strSQL = "SELECT * FROM Candidates WHERE Candidates.FirstName=´" & strFirstName & _ "´ AND Candidates.FamilyName=´" & strFamilyName & "´" ´MsgBox strSQL CurrentDb.QueryDefs("qryCandidates").SQL = strSQL Set recqry = CurrentDb().OpenRecordset("qryCandidates") If recqry.RecordCount = 0 Then Exit Sub End If strMessage = "השם שהכנסת כבר קיים במערכת. האם לשמור בכל זאת?" intOptions = vbQuestion + vbOKCancel bytChoice = MsgBox(strMessage, intOptions) If bytChoice = vbCancel Then Cancel = True End If End Sub
 
למעלה