Run-time Error '3061'- Expected 1 (1 Viewer)

NewfieSarah

Registered User.
Local time
Today, 08:49
Joined
Feb 11, 2005
Messages
193
I have a error I need help with. Here is my code for my Global, and My Form Current: See the red for the Error Line, that show up in the VBE and the Blue is the code related to that line. I am using access 2003
Code:
'Declare all variables for right-side record counter
Dim bdg As DAO.Recordset
[COLOR="Blue"]Dim swr As DAO.Recordset[/COLOR]
Dim wtr As DAO.Recordset
Dim dmo As DAO.Recordset
''Dim dvt As DAO.Recordset
Dim occ As DAO.Recordset
Dim fre As DAO.Recordset
Dim swrlat As DAO.Recordset
Dim wrtlat As DAO.Recordset

Dim bdgCount As Integer
[COLOR="blue"]Dim swrcount As Integer[/COLOR]
Dim wtrcount As Integer
Dim dmocount As Integer
Dim dvtcount As Integer
Dim occcount As Integer
Dim frecount As Integer
Dim countswr As Integer 'laterial counter
Dim countwtr As Integer 'laterial counter

Dim sqlbdg As String
[COLOR="blue"]Dim sqlswr As String[/COLOR]
Dim sqlwtr As String
Dim sqldmo As String
''Dim sqldvt As String
Dim sqlocc As String
Dim sqlfre As String
Dim sqlswrlat As String
Dim sqlwtrlat As String

Dim db As DAO.Database
Code:
Private Sub Form_Current()
Set db = CurrentDb()
'Use SQL strings to pull data from the tables
sqlbdg = "SELECT [Building].[PIN] FROM Building WHERE [Building].[PIN]='" & Me![ADDRESS3] & "' ;"
[COLOR="blue"]sqlswr = "SELECT [Sewerform].[PIN] FROM [SEWER SERVICE LATERALS] WHERE [Sewerform].[PIN]='" & Me![ADDRESS3] & "' ;"[/COLOR]
sqlwtr = "SELECT [water].[PIN] FROM [WATER SERVICE LATERALS] WHERE [water].[PIN]='" & Me![ADDRESS3] & "' ;"
sqlswrlat = "SELECT [SewerMain].[PIN] FROM [SEWER MAIN PRBLEMS] WHERE [SewerMain].[PIN]='" & Me![ADDRESS3] & "' ;"
sqlwtrlat = "SELECT [WaterMain].[PIN] FROM [WATER MAIN PROBLEMS] WHERE [WaterMain].[PIN]='" & Me![ADDRESS3] & "' ;"
sqldmo = "SELECT [Demolition Permits].[PID] FROM [Demolition Permits] WHERE [Demolition Permits].[PID]='" & Me![ADDRESS3] & "' ;"
''There is no PIN field in the development table ==> sqlwtr = "SELECT [Development Permits].[PIN] FROM [Development Permits] WHERE [Development Permits].[PIN]='" & Me![ADDRESS3] & "' ;"
sqlocc = "SELECT [Occupancy].[PIN] FROM Occupancy WHERE [Occupancy].[PIN]='" & Me![ADDRESS3] & "' ;"
sqlfre = "SELECT [Freeze].[PIN] FROM Freeze WHERE [FREEZE].[PIN]='" & Me![ADDRESS3] & "' ;"

Set bdg = db.OpenRecordset(sqlbdg, dbOpenSnapshot)
[COLOR="Red"]Set swr = db.OpenRecordset(sqlswr, dbOpenSnapshot)[/COLOR]
Set wtr = db.OpenRecordset(sqlwtr, dbOpenSnapshot)
Set dmo = db.OpenRecordset(sqldmo, dbOpenSnapshot)
''Set dvt = db.OpenRecordset(sqldvt, dbOpenSnapshot)
Set occ = db.OpenRecordset(sqlocc, dbOpenSnapshot)
Set fre = db.OpenRecordset(sqlfre, dbOpenSnapshot)
Set swrlat = db.OpenRecordset(sqlswrlat, dbOpenSnapshot)
Set wrtlat = db.OpenRecordset(sqlwtrlat, dbOpenSnapshot)

'Building recordset
On Error Resume Next
If bdg.EOF And bdg.BOF = True Then
    bdgCount = 0
Else

With bdg
    .MoveFirst
    .MoveLast
    bdgCount = .RecordCount
End With

End If

[COLOR="blue"]'Sewer recordset
On Error Resume Next
If swr.EOF And swr.BOF = True Then
    swrcount = 0
Else

With swr
    .MoveFirst
    .MoveLast
    swrcount = .RecordCount
End With

End If[/COLOR]

'Water recordset
On Error Resume Next
If wtr.EOF And wtr.BOF = True Then
    wtrcount = 0
Else

With wtr
    .MoveFirst
    .MoveLast
    wtrcount = .RecordCount
End With

End If
'Sewer laterial recordset
On Error Resume Next
If swrlat.EOF And swrlat.BOF = True Then
    countswr = 0
Else

With swrlat
    .MoveFirst
    .MoveLast
    countswr = .RecordCount
End With

End If

'Water laterial recordset
On Error Resume Next
If wrtlat.EOF And wrtlat.BOF = True Then
    countwtr = 0
Else

With wrtlat
    .MoveFirst
    .MoveLast
    countwtr = .RecordCount
End With

End If
 
'Demolition recordset
On Error Resume Next
If dmo.EOF And dmo.BOF = True Then
    dmocount = 0
Else

With dmo
    .MoveFirst
    .MoveLast
    dmocount = .RecordCount
End With

End If

'Development recordset
''On Error Resume Next
''If dvt.EOF And dvt.BOF = True Then
    dvtcount = 0
''Else

''With dvt
''    .MoveFirst
''    .MoveLast
''    dvtcount = .RecordCount
''End With

''End If

'Occupancy recordset
On Error Resume Next
If occ.EOF And occ.BOF = True Then
    occcount = 0
Else

With occ
    .MoveFirst
    .MoveLast
    occcount = .RecordCount
End With

End If

'Freeze recordset
On Error Resume Next
If fre.EOF And fre.BOF = True Then
    frecount = 0
Else

With fre
    .MoveFirst
    .MoveLast
    frecount = .RecordCount
End With

End If

'Set the values of the recordcounts to the appropriate text boxes

txtbdgcount.SetFocus
txtbdgcount.Text = bdgCount
[COLOR="blue"]txtswrcount.SetFocus
txtswrcount.Text = swrcount[/COLOR]
txtwtrcount.SetFocus
txtwtrcount.Text = wtrcount
txtdmocount.SetFocus
txtdmocount.Text = dmocount
txtdvtcount.SetFocus
txtdvtcount.Text = dvtcount
txtocccount.SetFocus
txtocccount.Text = occcount
txtfrecount.SetFocus
txtfrecount.Text = frecount
txtcountswr.SetFocus
txtcountswr.Text = countswr
txtcountwtr.SetFocus
txtcountwtr.Text = countwtr


PARID.SetFocus


' Provide a record counter for using with
' custom navigation buttons (when not using
' Access built in navigation)

    Dim rst As DAO.Recordset
    Dim lngCount As Long

    Set rst = Me.RecordsetClone

    With rst
        .MoveFirst
        .MoveLast
        lngCount = .RecordCount
    End With
    
'Show the result of the record count in the text box (txtRecordNo)

    Me.Text34 = "Record " & Me.CurrentRecord & " of " & lngCount
End Sub
 

The Stoat

The Grim Squeaker
Local time
Today, 12:19
Joined
May 26, 2004
Messages
239
Hi,

Changing the SQL string to include the correct bracketing should cure it. Also be aware that you are passing the parameter as a string by using the single quotes around
Me![ADDRESS3]. That's fine if PIN is text however if it is Numeric lose the single quotes '

sqlswr = "SELECT [Sewerform].[PIN] FROM [SEWER SERVICE LATERALS] WHERE ((([Sewerform].[PIN])='" & Me![ADDRESS3] & "'))"
 

NewfieSarah

Registered User.
Local time
Today, 08:49
Joined
Feb 11, 2005
Messages
193
Thanks for the tips however it didnt work, still got the same message as before.
 

Bat17

Registered User.
Local time
Today, 12:19
Joined
Sep 24, 2004
Messages
1,687
Is [SEWER SERVICE LATERALS] a query with a parameter in it?

Peter
 

The Stoat

The Grim Squeaker
Local time
Today, 12:19
Joined
May 26, 2004
Messages
239
OK i can see the problem.

Your where clause is not working against the table you are selecting from.

you need to replace sewerform with the table name

"SELECT [SEWER SERVICE LATERALS].[PIN] FROM [SEWER SERVICE LATERALS] WHERE ((([SEWER SERVICE LATERALS].[PIN])='" & Me![ADDRESS3] & "'))"
 

Users who are viewing this thread

Top Bottom