Results 1 to 3 of 3

Thread: Code or query!?

  1. #1
    Join Date
    Apr 2002
    Location
    Portugal
    Posts
    146

    Unanswered: Code or query!?

    Hi,



    I see very often this or like this SQL statments in code:

    strSQL="Delete * From tblTable;"
    docmd.execute strSQL


    My question is, isn't more simple create a query and then call it by code!?

    Or is there any diference, and for some reason most of the people creates the querys in code!

    Can you explain me the diferences!?

    Thanks!

  2. #2
    Join Date
    Feb 2002
    Posts
    403
    I think SQL gives you better control than a query. There are some instances where the query will not run properly but the string in code will, such as changing recordsources in combo boxes based on another combo box in the form.

    The other reason could be a more simple one, which I personally like, which is by placing the sql in code I cut down the number of objects in my application.

    There are some SQL statements that cannot be run except for code.

  3. #3
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    another thought would be the possibility to use transactions (not in your sample code though) using the execute method of the database object and begin, commit and roll back transactions on the parent workspace.

    dim wrk as workspace
    dim dbs as database

    set wrk = workspaces(0)
    set dbs = wek.databases(0)

    wrk.begintrans

    dbs.execute sql1, dbfailonerror
    dbs.execute sql2, dbfailonerror
    ...

    wrk.committrans

    set dbs = nothing
    set wrk = nothing

Posting Permissions

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