aziz rasul
08-23-2007, 05:53 AM
I have the following code: -
Dim strSQL As String
Dim qdf As DAO.QueryDef
Dim intModelCodes As Integer
Dim strMin As String
Dim strMax As String
Dim fld As Field
If Not IsNull(Me.MasterLicenseeCode) And Not IsNull(Me.cboDescriptor) And Not IsNull(Me.cboType) Then
strSQL = "SELECT tblProducts.ModelCode FROM tblProducts WHERE (((tblProducts.ProductIDprod) Like '" & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor & "*'));"
Call DeleteQuery("qryModelCodes")
Set qdf = CurrentDb.CreateQueryDef("qryModelCodes", strSQL)
intModelCodes = DCount("[ModelCode]", "qryModelCodes")
qdf.SQL = "SELECT Min(tblProducts.ModelCode) AS MinOfModelCode, Max(tblProducts.ModelCode) AS MaxOfModelCode " & _
"FROM tblProducts " & _
"HAVING (((tblProducts.ProductIDprod) Like '" & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor & "*'));"
For Each fld In qdf.Fields
If fld.Name = "MinOfModelCode" Then
strMin = fld.Value 'Run time error 3219 - Invalid operation
ElseIf fld.Name = "MaxOfModelCode" Then
strMax = fld.Value
End If
Next fld
Me.txtMin = strMin
Me.txtMax = strMax
If intModelCodes = 0 Then
Me.txtModelCodes = "There are no models for " & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor
ElseIf intModelCodes = 1 Then
Me.txtModelCodes = "There is " & intModelCodes & " model for " & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor
ElseIf intModelCodes > 1 Then
Me.txtModelCodes = "There are " & intModelCodes & " models for " & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor
End If
'CurrentDb.QueryDefs.Delete qdf.Name
Else
Me.txtModelCodes = ""
End If
Does anyone know why I'm getting the error?
Dim strSQL As String
Dim qdf As DAO.QueryDef
Dim intModelCodes As Integer
Dim strMin As String
Dim strMax As String
Dim fld As Field
If Not IsNull(Me.MasterLicenseeCode) And Not IsNull(Me.cboDescriptor) And Not IsNull(Me.cboType) Then
strSQL = "SELECT tblProducts.ModelCode FROM tblProducts WHERE (((tblProducts.ProductIDprod) Like '" & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor & "*'));"
Call DeleteQuery("qryModelCodes")
Set qdf = CurrentDb.CreateQueryDef("qryModelCodes", strSQL)
intModelCodes = DCount("[ModelCode]", "qryModelCodes")
qdf.SQL = "SELECT Min(tblProducts.ModelCode) AS MinOfModelCode, Max(tblProducts.ModelCode) AS MaxOfModelCode " & _
"FROM tblProducts " & _
"HAVING (((tblProducts.ProductIDprod) Like '" & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor & "*'));"
For Each fld In qdf.Fields
If fld.Name = "MinOfModelCode" Then
strMin = fld.Value 'Run time error 3219 - Invalid operation
ElseIf fld.Name = "MaxOfModelCode" Then
strMax = fld.Value
End If
Next fld
Me.txtMin = strMin
Me.txtMax = strMax
If intModelCodes = 0 Then
Me.txtModelCodes = "There are no models for " & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor
ElseIf intModelCodes = 1 Then
Me.txtModelCodes = "There is " & intModelCodes & " model for " & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor
ElseIf intModelCodes > 1 Then
Me.txtModelCodes = "There are " & intModelCodes & " models for " & Me.MasterLicenseeCode & "-" & Me.cboType & Me.cboDescriptor
End If
'CurrentDb.QueryDefs.Delete qdf.Name
Else
Me.txtModelCodes = ""
End If
Does anyone know why I'm getting the error?