Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time Error '3061'- Expected 1 1

Status
Not open for further replies.

NewfieSarah

Programmer
Feb 7, 2005
147
CA
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] & "' ;"
sqlswr = "SELECT [Sewerform].[PIN] FROM [SEWER SERVICE LATERALS] WHERE [Sewerform].[PIN]='" & Me![ADDRESS3] & "' ;"
[COLOR=blue]sqlwtr = "SELECT [water].[PIN] FROM [WATER SERVICE LATERALS] WHERE [water].[PIN]='" & Me![ADDRESS3] & "' ;"[/color]
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
 
I suspect you will get similar or other errormessages also from most of the following sql statements too, cause you have one table name in the From clause, but another one in the select clause and where clause.

[tt]"SELECT [water].[PIN] FROM [WATER SERVICE LATERALS] WHERE [water].[PIN]='" & Me![ADDRESS3] & "' ;"[/tt]

Use the same table name all the places, or join the tables needed - when doing selects from one table, there's no need to reference them in select and where clause, only use the field name.

[tt]select pin from <CorrecTableName> where pin = '" & me!address3 & "'"[/tt]

Roy-Vidar
 
Yeah However what I have there is SELECT [water].[PIN] (Select pin from the water form) FROM [WATER SERVICE LATERALS] (from the table water service lateral) WHERE [water].[PIN]= '" & Me![ADDRESS3] & "' ;" (where the pin on the water form is equal to the address3 field on this form.
Does that make sence. I think it does. I selected the pin from the form to match the table where it is equal to the address field. Maybe I am missing something?? HELP???
 
I have real problems trying to answer this - I'd suggest try out with either the correct table name in all three places (as in the first sql statement of this lengthy code), or drop tablenames everywhere but the From clause. Then do a bit of reading on SQL, try out the the different statements in the query thingie in Access - if they don't work there, they won't work in code either ...

If you're after getting form control contents, do that just with form control references

[tt]me!txtSomeControl.value = forms!someotherform!txtSomeControl.value[/tt]

Roy-Vidar
 
Thanks for all the help RoyVidar, however I figured out the problem, I had to change my form name water to my table name and it works just great now. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top