Kim Z. said:
Okay, thank you. That helped. However, now I have this function
with all these methods that went with the "table" (I guess), so I'm
not sure how to replace them. Does anyone have any suggestions, or
can someone tell me where to go to get the information?
Here is the entire function I'm working on:
Function rms_ValidateNewBox(ByVal boxid As String) As Integer
' validate that new boxid is not in table
Dim mydb As Database, MyTable As DAO.Recordsets
rms_ValidateNewBox = 0
Set mydb = CurrentDb
Set MyTable = mydb.TableDefs("tblboxes")
MyTable.Index = "PrimaryKey"
MyTable.Seek "=", boxid
If MyTable.NoMatch Then rms_ValidateNewBox = -1
MyTable.Close
End Function
Thanks for any help.
Try this version, which is a pretty close translation of what you had:
'----- start of revised code #1 -----
Function rms_ValidateNewBox(ByVal boxid As String) As Integer
' validate that new boxid is not in table
Dim mydb As Database, MyTable As DAO.Recordset
rms_ValidateNewBox = 0
Set mydb = CurrentDb
Set MyTable = mydb.OpenRecordset("tblboxes", dbOpenTable)
MyTable.Index = "PrimaryKey"
MyTable.Seek "=", boxid
If MyTable.NoMatch Then rms_ValidateNewBox = -1
MyTable.Close
Set MyTable = Nothing
Set mydb = Nothing
End Function
'----- end of revised code #1 -----
However, I wouldn't do it that way. I'd probably do it something like
this:
'----- start of revised code #2 -----
Function rms_ValidateNewBox(ByVal boxid As String) As Integer
' validate that new boxid is not in table
Dim mydb As Database, MyTable As DAO.Recordset
Set mydb = CurrentDb
Set MyTable = mydb.OpenRecordset( _
"SELECT * FROM tblboxes WHERE boxid = '" & boxid & "'", _
dbOpenSnapshot)
With MyTable
rms_ValidateNewBox = .EOF
.Close
End With
Set MyTable = Nothing
Set mydb = Nothing
End Function
'----- end of revised code #2 -----