Hi Folks,
I was attempting to cleanup code and make it more efficient. So I ran the Performance Analyzer on one of the forms which contains significant amount of code. The suggestion was to declare the class module as Option Explicit.
When trying to compile, I was directed to elements which weren't declared. So I declared them. Then when I tried to compile again, I got a Type Mismatch in a DLookup line which ran fine before the Option Explicit directive.
Code snippet follows:
MemFiledNum and ImpFieldNum are both declared as Long as are their counterparts in the recordset impmap.
I've tried declaring app as Application and inserting it in front of DLookup and Nz. But that didn't help.
Now here's where I'm confused. When I substitute the actual table in the DLookup statement replacing the declared recordset (impmap), the code compiles.
Does anyone know why this is so? Again without the Option Explicit statement, the original code compiled and ran.
Thanks,
Vic
I was attempting to cleanup code and make it more efficient. So I ran the Performance Analyzer on one of the forms which contains significant amount of code. The suggestion was to declare the class module as Option Explicit.
When trying to compile, I was directed to elements which weren't declared. So I declared them. Then when I tried to compile again, I got a Type Mismatch in a DLookup line which ran fine before the Option Explicit directive.
Code snippet follows:
Code:
Dim db as DAO.Database
Dim impmap As DAO.Recordset
Dim ImpFieldNum As Long
Dim MemFieldNum As Long
set db as CurrentDb
Set impmap = db.OpenRecordset("tblImportFieldMapTal", dbOpenDynaset, dbSeeChanges)
MemFieldNum = Nz(DLookup("MemFieldNum", impmap, "ImpFieldNum=" & ImpFieldNum), 0)
MemFiledNum and ImpFieldNum are both declared as Long as are their counterparts in the recordset impmap.
I've tried declaring app as Application and inserting it in front of DLookup and Nz. But that didn't help.
Now here's where I'm confused. When I substitute the actual table in the DLookup statement replacing the declared recordset (impmap), the code compiles.
Code:
MemFieldNum = Nz(DLookup("MemFieldNum", "tblImportFieldMapTal", "ImpFieldNum=" & ImpFieldNum), 0)
Does anyone know why this is so? Again without the Option Explicit statement, the original code compiled and ran.
Thanks,
Vic