I needed to separate an Access 2007 database, tables from forms, queries, programing, etc.
No problem doing that except that a bit of code in BeforeUpdate that checks to make sure entry is not a duplicate entry, will no longer work. I've tried every suggestion I could find and nothing works. When I reattach tables to the rest of program the code runs perfectly. Very frustrating!!! What can I do???
On Error GoTo Form_BeforeUpdate_Err
Dim dbs As Database
Dim tdf As TableDef
Dim rst As Recordset
Dim strSeek As String
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("MyTable")
Set rst = tdf.OpenRecordset(dbOpenTable)
strSeek = Forms![MyForm]![MyName]
MyLen = Len(strSeek)
rst.Index = "Name"
rst.Seek "=", strSeek
If rst.Index = "" Then
rst.Close
Set rst = Nothing
Exit Sub
ElseIf rst.NoMatch Then
'MsgBox "NO MATCH FOUND"
rst.Close
Set rst = Nothing
Exit Sub
Else
MsgBox ("I have found this Name, " & "'" & strSeek & "'" & _
vbCrLf & vbCrLf & "already listed in your database! " & vbCrLf & vbCrLf & _
"I will clear this name and reset Name for a new entry.")
SendKeys "{ESC 3}"
DoCmd.CancelEvent
rst.Close
End If
Set dbs = Nothing
Form_BeforeUpdate_Exit:
Exit Sub
Form_BeforeUpdate_Err:
MsgBox Error$
Resume Form_BeforeUpdate_Exit
End Sub
No problem doing that except that a bit of code in BeforeUpdate that checks to make sure entry is not a duplicate entry, will no longer work. I've tried every suggestion I could find and nothing works. When I reattach tables to the rest of program the code runs perfectly. Very frustrating!!! What can I do???
On Error GoTo Form_BeforeUpdate_Err
Dim dbs As Database
Dim tdf As TableDef
Dim rst As Recordset
Dim strSeek As String
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("MyTable")
Set rst = tdf.OpenRecordset(dbOpenTable)
strSeek = Forms![MyForm]![MyName]
MyLen = Len(strSeek)
rst.Index = "Name"
rst.Seek "=", strSeek
If rst.Index = "" Then
rst.Close
Set rst = Nothing
Exit Sub
ElseIf rst.NoMatch Then
'MsgBox "NO MATCH FOUND"
rst.Close
Set rst = Nothing
Exit Sub
Else
MsgBox ("I have found this Name, " & "'" & strSeek & "'" & _
vbCrLf & vbCrLf & "already listed in your database! " & vbCrLf & vbCrLf & _
"I will clear this name and reset Name for a new entry.")
SendKeys "{ESC 3}"
DoCmd.CancelEvent
rst.Close
End If
Set dbs = Nothing
Form_BeforeUpdate_Exit:
Exit Sub
Form_BeforeUpdate_Err:
MsgBox Error$
Resume Form_BeforeUpdate_Exit
End Sub
Last edited: