Application-defined or object-defined error (1 Viewer)

chanvba

New member
Local time
Yesterday, 20:32
Joined
Jul 25, 2014
Messages
9
HI

I am new to VBA, I am trying to populate 10 textboxes with values from a table. I am getting "Application-defined or object-defined error" when I open the form.
Can you please find where is it going wrong?


Text boxes are named compl_01 to compl_10.
And NUMer value in sql is supposed to change to NUM01 …NUM10 with each loop.


Thanks a lot

If Measure = "CIS" Then

'Const cintLastTextBoxNum As Integer = 10
Dim i As Integer
Dim qdf As QueryDef
Dim rs As DAO.Recordset
Dim COMPl As String
Dim COMPla As String
Dim NUMer As String
Dim dba As Database
Dim sqlb As String

For i = 1 To 10
NUMer = "NUM" & Format(i, "00")
COMPla = "compl_" & Format(i, "00")

sqlb = "SELECT DISTINCT HEDIS_HYBRID_CMPL_ALL.[compliance]" _
& "FROM [HEDIS_HYBRID_CMPL_ALL]" _
& "WHERE HEDIS_HYBRID_CMPL_ALL.ENCRYPT_ID = '" & Left(Tracking_ID, 7) & "'" _
& "And HEDIS_HYBRID_CMPL_ALL.CMPL_RULE_ID = '" & NUMer & "'"
Set dba = CurrentDb
Set qdf = dba.CreateQueryDef("", sqlb)
Set rs = qdf.OpenRecordset(dbOpenSnapshot)
COMPl = ""
Do While Not rs.EOF
If COMPl = "" Then
COMPl = rs![compliance].Value
Else
COMPl = "COMPl" & "," & rs![compliance].Value
End If

rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set dba = Nothing
Set qdf = Nothing
Forms(stDocName).COMPla = COMPl
Next i
End If
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:32
Joined
Jul 9, 2003
Messages
16,280
Add the following message box as shown:-

MsgBox " >>> " & sqlb
Set dba = CurrentDb

and post the text from the message generated here.
 

chanvba

New member
Local time
Yesterday, 20:32
Joined
Jul 25, 2014
Messages
9
Thank you Gizmo,

Here is the message i got :

>>>SELECT DISTINCT HEDIS_HYBRID_CMPL_ALL.[compliance]FROM [HEDIS_HYBRID_CMPL_ALL] WHERE HEDIS_HYBRID_CMPL_ALL.ENCRYPT_ID = 'CIMP109' And HEDIS_HYBRID_CMPL_ALL.CMPL_RULE_ID = 'NUM01'

When i click OK, i again get original error message "Application-defined or object-defined error"

Thanks,
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:32
Joined
Jul 9, 2003
Messages
16,280
Change this row from:-
sqlb = "SELECT DISTINCT HEDIS_HYBRID_CMPL_ALL.[compliance]" _

To:-
sqlb = "SELECT DISTINCT HEDIS_HYBRID_CMPL_ALL.[compliance] " _
 

chanvba

New member
Local time
Yesterday, 20:32
Joined
Jul 25, 2014
Messages
9
Thank you,
I modified as you suggested, and the msgbox I received is attached.
 

Attachments

  • msgbox.JPG
    msgbox.JPG
    23.9 KB · Views: 541

GinaWhipp

AWF VIP
Local time
Yesterday, 20:32
Joined
Jun 21, 2011
Messages
5,899
Try this...

Code:
sqlb = "SELECT DISTINCT HEDIS_HYBRID_CMPL_ALL.[compliance] " & _
"FROM [HEDIS_HYBRID_CMPL_ALL] " & _
"WHERE HEDIS_HYBRID_CMPL_ALL.ENCRYPT_ID = '" & Left(Tracking_ID, 7) & "' " & _
"And HEDIS_HYBRID_CMPL_ALL.CMPL_RULE_ID = '" & NUMer & "'"
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 01:32
Joined
Jul 9, 2003
Messages
16,280
HEDIS_HYBRID_CMPL_ALL.ENCRYPT_ID

And
HEDIS_HYBRID_CMPL_ALL.CMPL_RULE_ID

Look like they are supposed to be numbers?

Could you post some examples of values they contain?
 

chanvba

New member
Local time
Yesterday, 20:32
Joined
Jul 25, 2014
Messages
9
Both ENCRYPT_ID and CMPL_RULE_ID are string variables. I do not have any field with numbers.
 

chanvba

New member
Local time
Yesterday, 20:32
Joined
Jul 25, 2014
Messages
9
Sorry forgot to post examples:
ENCRYPT_ID have values like- CIMP001, CIMP002, CIMP003 etc
CMPL_RULE_ID have values NUM01, NUM02 ..... NUM10
 

chanvba

New member
Local time
Yesterday, 20:32
Joined
Jul 25, 2014
Messages
9
Hi Gina, Thank you, I tried your sql code, its the same as before.

I guess i am not able to assign query value to the text field.
either do loop failing or
Forms(stDocName).COMPla = COMPl
is not able to pass on the result to the text field.
its my guess , I am not sure.

If i do not use for next cycle, instead write code 10 times for NUM01 to NUM10 for 10 text fields, it works fine, but each time i change
Dim qdf As QueryDef
Dim rs As DAO.Recordset
Dim COMPl As String
Dim COMPla As String
Dim NUMer As String
Dim dba As Database
Dim sqlb As String

to 10 different names for 10 different codes, and it works. But as soon as i use for next loop to do it in one step , i get Application-defined or object-defined error
 

GinaWhipp

AWF VIP
Local time
Yesterday, 20:32
Joined
Jun 21, 2011
Messages
5,899
What line does it stop on when you get that error?
 

chanvba

New member
Local time
Yesterday, 20:32
Joined
Jul 25, 2014
Messages
9
I did some debugging, the code was stopping at:
Forms(stDocName).COMPla = COMPl
i changed to :
Forms(stDocName).controls(COMPla).Value = COMPl

then it worked like charm.

Thanks a lot to you and Gizmo for help
 

Users who are viewing this thread

Top Bottom