Here is my problem.
I have a command button (cmdSitePhotos) that is on a subform (xsfrmDataDisp).
When the form/subform is opened, I want a query to be run (I have function executed on the On_Current of the subform properties). The purpose of the query is to seach a table for photos related to that site. If there are photos available for the site, I want the command button to be enabled and for a caption to appear on the button. If there are not photos for that site, then I want the button to be disabled and a different caption to appear.
The Master and Child field- link is via the SiteNum, which I also want to pass to the SQL statement as the parameter.
I have copied the code that I cannot get working. ...Help, please!
Ultimately, if there are photos (and the button is enable, when it is clicked, I want a subform opened that will use the query as its source ---- should I pass the recordset to the new subform or just run the sql statement again?
Thanks in advance, all help is appreciated.
DJ
--------
Private Sub QryPhotos()
On Error GoTo ErrorHandler
Dim rs As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim intFileNum As Integer
Dim lngCount As Long
Dim sSQL As String
Set rs = New ADODB.Recordset
Set cnn = New ADODB.Connection
Set cnn = CurrentProject.Connection
sSQL = "SELECT tblPhoto.SiteNum, tblPhoto.FileName, tblPhoto.PhotoCaption FROM tblPhoto WHERE (((tblPhoto.SiteNum)= [Forms]![xsfrmDataDisp]![tbxSiteNum]))"""
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly
'Check to see if there are any records
Debug.Print rs.RecordCount
If rs.RecordCount < 1 Then
cmdSitePhotos.Caption = "No Photos Available"
cmdSitePhotos.Enabled = False
Else
cmdSitePhotos.Caption = "View Site Photos"
cmdSitePhotos.Enabled = True
End If
'Close the Recordset and Connection Objects
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Exit Sub
ErrorHandler:
Set rs = Nothing
Set cnn = Nothing
Err.Clear
End Sub
--------------------------------
I have a command button (cmdSitePhotos) that is on a subform (xsfrmDataDisp).
When the form/subform is opened, I want a query to be run (I have function executed on the On_Current of the subform properties). The purpose of the query is to seach a table for photos related to that site. If there are photos available for the site, I want the command button to be enabled and for a caption to appear on the button. If there are not photos for that site, then I want the button to be disabled and a different caption to appear.
The Master and Child field- link is via the SiteNum, which I also want to pass to the SQL statement as the parameter.
I have copied the code that I cannot get working. ...Help, please!
Ultimately, if there are photos (and the button is enable, when it is clicked, I want a subform opened that will use the query as its source ---- should I pass the recordset to the new subform or just run the sql statement again?
Thanks in advance, all help is appreciated.
DJ
--------
Private Sub QryPhotos()
On Error GoTo ErrorHandler
Dim rs As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim intFileNum As Integer
Dim lngCount As Long
Dim sSQL As String
Set rs = New ADODB.Recordset
Set cnn = New ADODB.Connection
Set cnn = CurrentProject.Connection
sSQL = "SELECT tblPhoto.SiteNum, tblPhoto.FileName, tblPhoto.PhotoCaption FROM tblPhoto WHERE (((tblPhoto.SiteNum)= [Forms]![xsfrmDataDisp]![tbxSiteNum]))"""
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly
'Check to see if there are any records
Debug.Print rs.RecordCount
If rs.RecordCount < 1 Then
cmdSitePhotos.Caption = "No Photos Available"
cmdSitePhotos.Enabled = False
Else
cmdSitePhotos.Caption = "View Site Photos"
cmdSitePhotos.Enabled = True
End If
'Close the Recordset and Connection Objects
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
Exit Sub
ErrorHandler:
Set rs = Nothing
Set cnn = Nothing
Err.Clear
End Sub
--------------------------------