Okay, how about trying the technique in post 11 to get the finished SQL?
I added the debug function, but it didn't do anything when I ran it. Here is the code.
Private Sub Display()
Dim strsql As String
Dim DAO As DAO.Database
Dim RS As DAO.Recordset
Dim LngCnt As Long
LngCnt = 0
Set DAO = OpenDatabase("W:\RCO\Databases\SQL_RCO_Database.ac cdb")
Debug.Print strsql
Set RS = DAO.OpenRecordset("SELECT * FROM dbo_TblRDStudyAuditDocument WHERE ID_D = '" & Me.ID_D & "'", dbOpenDynaset, dbSeeChanges)
LngCnt = RS.RecordCount
With RS
If LngCnt > 0 Then
.MoveFirst
.Index = "PK_TblRDStudyAuditDocument"
.Seek "=", ID_D
If .NoMatch Then
MsgBox ("No Match"), vbInformation, "ERROR: Display()"
Exit Sub
Else
Studyid = .Fields(1)
AuditDate = .Fields(2)
TxtSectionName = .Fields(3)
DocName = .Fields(4)
Comments = .Fields(5)
End If
End If
.Close
End With
Set DAO = Nothing
End Sub
You never actually populated the string. Modify or add these lines as appropriate:
strsql = "SELECT * FROM dbo_TblRDStudyAuditDocument WHERE ID_D = '" & Me.ID_D & "'"
Debug.Print strsql
Set RS = DAO.OpenRecordset(strsql, dbOpenDynaset, dbSeeChanges)
Shouldn't matter. The Debug.Print would just send empty string to the immediate window. The code should still have done everything else.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
I realize that, but the result is we don't have the string available to debug why the code doesn't work.
True, populating and using the variable could be helpful in debugging. Just wanted OP to be aware that if code is not working there is something more wrong then just the empty variable.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
What is the error description?
(Updated) Run-time error 91: Object variable or with block variable not set
That looks like a number, not a description.
Oh, you haven't set the database variable.
I updated the thread above after I wrote it. Sorry.
So where are we when you add back the code to set the database variable?
Added the scripted as you suggested so that is where we are at. I showed the error so I hope that helps.