Skip to content Skip to sidebar Skip to footer

Vba Access Error 91

I try to run this code Public Sub Production_UpdateStatus(ByVal lngProductionId As Long, _ ByVal NewProductionStatus As eProductionStatus) D

Solution 1:

You are closing a recordset object, oRst, that was never initialized with Set. Because you run an action query you do not need a recordset and it may have lingered from prior code versions.

On that same note, because you are passing literal values to an SQL query, consider parameterizing with DAO QueryDef parameters that avoids concatenation and quote enclosures:

Dim oDb As DAO.Database, qdef As DAO.QueryDef
Dim StrSql AsString, strProductionStatus AsString

GetCurrentProductionStatusString NewProductionStatus, strProductionStatus

Set oDb = CurrentDb

StrSql = "PARAMETERS strProductionStatusParam Text(255), lngProductionIdParam Long;" _
           & " UPDATE tProduction SET tProduction.Statut = [strProductionStatusParam]" _
           & " WHERE (tProduction.IdProduction = [lngProductionIdParam]);"Set qdef = oDb.CreateQueryDef("", StrSql)

qdef!strProductionStatusParam = strProductionStatus
qdef!lngProductionIdParam = lngProductionId

qdef.Execute dbFailOnError

Set qdef = NothingSet oDb = Nothing

Solution 2:

Try to remove the oRst related code lines. This variable is not initialized and not used.

Post a Comment for "Vba Access Error 91"