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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling module 1

Status
Not open for further replies.

jtfrier

Technical User
Jan 12, 2006
85
0
0
I have a Module in MS Access with this code and I need to know how to call it runing a query

Code:
Option Compare Database

Option Explicit

 

Public Sub RSLoop()

Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim varPart As String
Dim cntr As Long
Dim varDesc

On Error GoTo ErrorHere
     DoCmd.SetWarnings False
    Set rs = New ADODB.Recordset
    Set rs2 = New ADODB.Recordset
 
    rs.Open "SELECT Edmanmanruby.partno, Edmanmanruby.desc " & _
    "FROM Edmanmanruby " & _
    "ORDER BY Edmanmanruby.partno", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly

    rs.MoveFirst
    Do While Not rs.EOF
2       varPart = rs!partno
        cntr = 1
1       If rs!partno = varPart Then
            If cntr = 1 Then
                DoCmd.RunSQL "UPDATE tblDesc " & _
                            "SET descrip = '" & rs!desc & "' " & _
                            "WHERE (((tblDesc.partno) = '" & varPart & "'))"
            Else
                rs2.Open "SELECT tblDesc.descrip " & _
                      "FROM tblDesc " & _
                        "WHERE (((tblDesc.partno) = '" & varPart & "'))", CurrentProject.Connection
                varDesc = rs2!descrip
                rs2.Close
                DoCmd.RunSQL "UPDATE tblDesc " & _
                "SET descrip = '" & varDesc & "' & '" & rs!desc & "' WHERE (((tblDesc.partno) = '" & varPart & "'))"
            End If
            rs.MoveNext
            cntr = cntr + 1
            GoTo 1
        Else
            'rs.MoveNext
            GoTo 2
        End If
    Loop
    MsgBox "All Done"
ExitHere:
3   rs.Close
    'rs2.Close
    Set rs = Nothing
    Set rs2 = Nothing
    DoCmd.SetWarnings True
    Exit Sub
ErrorHere:
    MsgBox Err.Number & ": " & Err.Description
    Resume ExitHere
End Sub
 
A query may call a function not a sub.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
oh i just need to run the sub ty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top