D
Dirk Goldgar
Frank Dulk said:in the code I do lower the line in prominence of the mistake with
linked tables, because? how to solve?
-------------
Dim intDia Integer
Dim intMes Integer
Dim db Database
Dim rs Recordset
intDia = Day(umaData)
intMes = Month(umaData)
Set db = CurrentDb
Set rs = db.OpenRecordset (tabFeriadosFixos ", dbOpenTable)
rs.Index = PrimaryKey "
rs.Seek " =", intDia, intMes
If rs.NoMatch Then
E_FeriadoFixo = False
Else
E_FeriadoFixo = True
End If
rs.Close
You can't open a table-type recordset (as with dbOpenTable) directly on
a linked table, and thus can't use the Seek method. You have two
alternatives:
1. Open a dynaset instead, and use the FindFirst method instead of Seek.
2. Open a database object on the back-end database where the table is
actually stored, then open a table-type recordset from that database
object -- so you are not using the linked table at all -- and use the
Seek method on that recordset. The following KnowledgeBase article
shows how to do it:
http://support.microsoft.com/default.aspx?kbid=210266
However, although either of the above methods can be used to locate the
record you want, this may not be the best way to do what your posted
code seems to be doing. If the sole purpose of your recordset is to
determine whether a record exists in the table for the specified day and
month, then it would probably be faster just to use either DLookup on
the linked table, with a criteria string that specifies the day and
month, or to open a recordset on an SQL statement that attempts to
extract just the matching record(s). In other words, you might write
something like this:
E_FeriadoFixo = _
Not IsNull(DLookup( _
"CampoDia", _
"tabFeriadosFixos", _
"CampoDia=" & intDia & _
" AND CampoMes=" & intMes))
or like this:
Set db = CurrentDb
Set rs = db.OpenRecordset ( _
"SELECT CampoDia FROM tabFeriadosFixos " & _
"WHERE CampoDia=" & intDia & _
" AND CampoMes=" & intMes)
E_FeriadoFixo = Not Rs.EOF
rs.Close