keady2
06-11-2007, 08:22 AM
Okay so ... my title may explain my problem...I have a design master and then I have several replicas for each district to use outside of my own. The problem is only the design master is able to build a custom SQL string for the reports menu I have built ... the other districts get the error:
Error No. 3027: Description: Cannot update. Database or object is read-only.
Is there a way to build the custom SQL string in databases that are read-only? This is the code I have linked to the RUN REPORT button.
Private Sub Command158_Click()
On Error GoTo ErrorHandler
Dim strSQL As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim stdocname As String
strSQL = "SELECT datatbl.*, 'T' & [township] & 'R' & [range] AS [TR] " & _
"FROM datatbl " & _
"WHERE "
If Me.disemployee & "" <> "" Then
strSQL = strSQL & "[datatbl].[name]= '" & Me.disemployee & "' AND "
End If
If Me.distype & "" <> "" Then
strSQL = strSQL & "[datatbl].[function]=" & Me.distype.Column(0) & " AND "
End If
If Me.disgroup & "" <> "" Then
strSQL = strSQL & "[datatbl].[group]='" & Me.disgroup.Value & "' AND "
End If
If Me.disTR & "" <> "" Then
strSQL = strSQL & "('T' & [township] & 'R' & [range])='" & Me.disTR & "' AND "
End If
If Me.discode & "" <> "" Then
strSQL = strSQL & "[datatbl].[project code]= '" & Me.discode & " ' AND "
End If
If Me.txtstartdate & "" <> "" And Me.txtenddate & "" <> "" Then
strSQL = strSQL & "[datatbl].[Dateofwork] Between #" & Me.txtstartdate & _
"# And #" & Me.txtenddate & "#" & " AND "
Else
If Me.txtstartdate & "" <> "" Then
strSQL = strSQL & "[datatbl].[Dateofwork]=# " & Me.txtstartdate & "#" & _
" And "
End If
End If
If Right(strSQL, 5) = "HERE " Then
MsgBox "You did not select any criteria!", vbCritical, _
"Please select CUSTOM criteria"
DoCmd.CancelEvent
Exit Sub
Else
strSQL = Left(strSQL, Len(strSQL) - 5)
End If
Set db = CurrentDb
Set qdf = db.QueryDefs("qryforreport")
qdf.Sql = strSQL
Set qdf = Nothing
Set db = Nothing
If DCount("*", "qryforreport", "[RECORDID] > 1") > 0 Then
stdocname = "CustomReport"
DoCmd.OpenReport stdocname, acPreview
Else
MsgBox "There are no records that match this criteria", vbInformation, _
"No Records Found!"
End If
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
Thanks for any help on how to make this code run on a non-design master...
Edited 12-Jun-07 by geekgirlau. Reason: insert vba tags
Error No. 3027: Description: Cannot update. Database or object is read-only.
Is there a way to build the custom SQL string in databases that are read-only? This is the code I have linked to the RUN REPORT button.
Private Sub Command158_Click()
On Error GoTo ErrorHandler
Dim strSQL As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim stdocname As String
strSQL = "SELECT datatbl.*, 'T' & [township] & 'R' & [range] AS [TR] " & _
"FROM datatbl " & _
"WHERE "
If Me.disemployee & "" <> "" Then
strSQL = strSQL & "[datatbl].[name]= '" & Me.disemployee & "' AND "
End If
If Me.distype & "" <> "" Then
strSQL = strSQL & "[datatbl].[function]=" & Me.distype.Column(0) & " AND "
End If
If Me.disgroup & "" <> "" Then
strSQL = strSQL & "[datatbl].[group]='" & Me.disgroup.Value & "' AND "
End If
If Me.disTR & "" <> "" Then
strSQL = strSQL & "('T' & [township] & 'R' & [range])='" & Me.disTR & "' AND "
End If
If Me.discode & "" <> "" Then
strSQL = strSQL & "[datatbl].[project code]= '" & Me.discode & " ' AND "
End If
If Me.txtstartdate & "" <> "" And Me.txtenddate & "" <> "" Then
strSQL = strSQL & "[datatbl].[Dateofwork] Between #" & Me.txtstartdate & _
"# And #" & Me.txtenddate & "#" & " AND "
Else
If Me.txtstartdate & "" <> "" Then
strSQL = strSQL & "[datatbl].[Dateofwork]=# " & Me.txtstartdate & "#" & _
" And "
End If
End If
If Right(strSQL, 5) = "HERE " Then
MsgBox "You did not select any criteria!", vbCritical, _
"Please select CUSTOM criteria"
DoCmd.CancelEvent
Exit Sub
Else
strSQL = Left(strSQL, Len(strSQL) - 5)
End If
Set db = CurrentDb
Set qdf = db.QueryDefs("qryforreport")
qdf.Sql = strSQL
Set qdf = Nothing
Set db = Nothing
If DCount("*", "qryforreport", "[RECORDID] > 1") > 0 Then
stdocname = "CustomReport"
DoCmd.OpenReport stdocname, acPreview
Else
MsgBox "There are no records that match this criteria", vbInformation, _
"No Records Found!"
End If
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
Thanks for any help on how to make this code run on a non-design master...
Edited 12-Jun-07 by geekgirlau. Reason: insert vba tags