• Debug window (Access 97)

    Author
    Topic
    #375337

    This is probably an easy question. I am trying to use the debug window. I type the code in a module. Open the Debug window. Type in the name of the sub routine, hit enter and get “sub or function not defined”. I never use the debug window so what am I doing wrong???

    Viewing 1 reply thread
    Author
    Replies
    • #610440

      I presume you are trying to run the code you just entered. Have you compiled it and saved it? That would seem to be the most logical explanation for the error you are getting. In any event, you can simply choose the run command from the module toolbar or menubar and execute the code. Hope this helps.

    • #610442

      If you are using a sub procedure rather than a function I believe you need to use the CALL keyword as in Call subprocedurename. Alternatively you can change it to a function procedure and type ? functionname.

      • #610452

        This is the code I am using:

        Private Sub ListFields()

        Dim dbs As Database
        Dim dbfield As Field
        Dim tdf As TableDef

        Set dbs = CurrentDb
        Set tdf = dbs.TableDefs!tblspecialistinfo

        End Sub

        I want to get a list of fields in a table.

        When I put Call ListFields in the debug window and hit enter – now the error is “Expected porocedure, Not variable”

        It seems simple but I can’t seem to get it to work.

        • #610515

          [indent]


          Private Sub ListFields()


          [/indent]This is why. You are making your sub a Private sub, which can only be referenced from another procedure in the same module.

          If you want to run this sub from the debug window, you will need to change Private to Public or remove the word Private altogether.

          The easies way to test a procedure (without any parameters required) is to put your insertion point anywhere in the procedure and then press F5 to run the code or F8 to single step through the code.

          • #610593

            I give up, I have done everything everyone has suggested but I still get “function or sub not defined”. I took out private. I used F5 and F8 (it dings when I use these). I compiled all modules. This is what I am trying to run to get a listing of the fields in a table ( I added additional code):

            Public Sub ListFields()

            Dim dbs As Database
            Dim dbfield As Field
            Dim tdf As TableDef
            Dim tblName As String
            ‘select table to list

            tblName = GetTableName

            ‘quit if name is a null string
            If Trim(tblName) = “” Then Exit Sub

            Set dbs = CurrentDb
            Set tdf = dbs.TableDefs(tblName)
            Debug.Print “”
            Debug.Print “Table Name: ” & tdf.Name
            Debug.Print “”

            For Each dbfield In tdf.Fields
            Debug.Print dbfield.Name
            Next dbfield

            ‘release memory
            Set dbs = Nothing

            ‘open debug window
            SendKeys “^g”

            End Sub

            Function GetTableName()
            Dim strinput As String, strMsg As String, q As Variant
            ‘function returns table name or null string if user cancels

            strMsg = “Enter Table Name:”
            Repeat:
            strinput = InputBox(Prompt:=strMsg, _
            Title:=”List Table”, XPos:=2000, yPos:=2000)
            If strinput = “” Then
            GetTableName = “”
            Else
            q = MsgBox(“List able Named: ” & strinput, _
            vbYesNoCancel + vbDefaultButton1, “Report Table”)
            If q = vbCancel Then
            GetTableName = “”
            ElseIf q = vbNo Then
            GoTo Repeat
            Else
            ‘remove illegal leading and trailing spaces (if any)
            GetTableName = Trim(strinput)
            End If
            End If
            End Function

            • #610608

              I copied your code into an Access 97 database and it runs OK.

              Did you, by any chance, put the code into the module belonging to a form or report, or into a class module? You can’t just run procedures in those.

              You need to put the code in a standard module. In Access 97, activate the Modules tab of the Database window, and click New, or select Insert/Module (NOT Insert/Class Module). Then, you should be able to run a procedure by putting the insertion point somewhere in it and pressing F5 (or F8 to single-step through it).

            • #610611

              It worked perfectly. Thanks. I did put the code into a module belonging to a form. Then I put it into a class module. I did everything I wasn’t supposed to do. Thanks for your help.

            • #610629

              Just an afterthought:

              Many experts warn against the use of SendKeys. In this case, it’s probably not really important. But you can avoid the use of SendKeys to open the Debug window by replacing it with

              RunCommand acCmdDebugWindow

              Regards,
              Hans

    Viewing 1 reply thread
    Reply To: Debug window (Access 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: