Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Debug window (Access 97)

    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???

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Debug window (Access 97)

    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.
    Wendell

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    NYC,USA,Earth
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Debug window (Access 97)

    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.

  4. #4
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Debug window (Access 97)

    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.

  5. #5
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Debug window (Access 97)

    <hr>Private Sub ListFields()<hr>
    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.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  6. #6
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Debug window (Access 97)

    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

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Debug window (Access 97)

    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).

  8. #8
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Debug window (Access 97)

    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.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Debug window (Access 97)

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •