Results 1 to 7 of 7
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    simple syntax question

    i've got this simple sub that updates a field is a set of records to be a clean sequence of numbers; but I've got "something" wrong. All of the cycling thru number and updatinng of variable values foot correctly, it's the ".update" and ".edit" parts that aren't working (possibly the ".findfirst" also ?)

    any suggestionns would be a great help
    many thanks in advance, mark

    -------------------------------------
    Set Db = CurrentDb()
    Set rst = Db.OpenRecordset("SELECT tbeAdditionalPages.Printorder, tbeAdditionalPages.BaseCatalogSheet " & _
    "FROM tbeAdditionalPages " & _
    "WHERE tbeAdditionalPages.type = '" & Forms![frmSpec].[Type] & "';")

    With rst
    vCnt = DCount("[Type]", "tbeAdditionalPages", "[Type] = '" & Forms![frmSpec].Type & "'")
    vCntLoop = 1
    vCntPrintOrder = vCnt

    Do While vCntLoop <= vCnt
    Dim strSearch As String
    strSearch = DMax("[PrintOrder]", "tbeAdditionalPages", "[Type] = '" & Forms![frmSpec].Type & "'")
    .FindFirst strSearch
    .edit
    ![Printorder] = vCntPrintOrder
    vCntPrintOrder = vCntPrintOrder - 1
    .Update
    vCntLoop = vCntLoop + 1


    MsgBox vCntLoop & " - " & vCntPrintOrder
    Loop
    End With

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you'd better step into the code to see what happened.

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    2 notes:

    I've revised the lines in the middle of the code from:

    Dim strSearch As String
    strSearch = DMax("[PrintOrder]", "tbeAdditionalPages", "[Type] = '" & Forms![frmSpec].Type & "'")
    .FindFirst strSearch
    .edit

    to be:

    Dim strSearch As String
    .FindFirst DMax("[PrintOrder]", "tbeAdditionalPages", "[Type] = '" & Forms![frmSpec].Type & "'")
    .edit

    (it's definetly the findfirst line that is giving me trouble - at least I think it is...)


    second:
    I'm not sure how to step-thru
    I opened both the form and the VBA editor (in seperate windows);
    I put a break point in the code above the line I'd like to start tracking;
    yet when I run the code (thru an event on the form), it seems to run thru to the end -without breaking so that I can step thru...
    Do you have any source that would be a good debugging tutorial for me?

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    set break point outside the loop. or on first line of you code.

    it is not syntax error. is it something in you logic, we can not check inside without data.

  5. #5
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    I moved the break to the very first line of code in the subroute ("Public Sub subname); it still did not "break"; it ran thru tot he end of the proceedure...

    I'm surprised that you think it's the logic since all of the code except for the record .findfirst/.edit/.update runs fine. If I comment those lines, and put watches in for all of the other variables... they run in the manner that I anticipated. Never-the-lass, I'm the newbie, and suprises can be a good thing (and a learning experience too)

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    here may be some additional help:

    "WHERE tbeAdditionalPages.type = '" & Forms![frmSpec].[Type] & "';"

    **if TYPE is anything other than a string, try this instead:
    "WHERE tbeAdditionalPages.type = " & Forms![frmSpec].[Type] & ";"


    strSearch = DMax("[PrintOrder]", "tbeAdditionalPages", "[Type] = '" & Forms![frmSpec].Type & "'")

    DMax does not return a string. Does your code error here? If not, it should. Try:
    strSearch = CStr(DMax("[PrintOrder]", "tbeAdditionalPages", "[Type] = '" & Forms![frmSpec].Type & "'"))


    .FindFirst strSearch

    This syntax is incorrect. You need an exact substitute for a WHERE clause, not just a value:
    Instead of .FindFirst(strSearch), try this: .FindFirst "[fieldname] = '" & strSearch & "'"



    I'm almost certain your firstfirst is not working because the syntax is incorrect. If you want to know for sure though, add

    if .nomatch=true then
    msgbox "this syntax is incorrect"
    'close rs
    exit sub
    end if


    break the code after the NOMATCH property and hover over the mouse over "NOMATCH" to see the result of your findfirst code.

  7. #7
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    lesson learned... (THANKS - you can be my hero for the day !)
    -m.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Simple query Question, please Help
    By iamraja5 in forum Forms
    Replies: 1
    Last Post: 03-16-2010, 05:04 AM
  2. Simple question
    By KenM in forum Queries
    Replies: 1
    Last Post: 11-10-2009, 03:32 PM
  3. Simple question?
    By roads.zx in forum Access
    Replies: 0
    Last Post: 10-15-2009, 04:56 PM
  4. Very simple question!
    By fiddley in forum Programming
    Replies: 2
    Last Post: 04-28-2009, 02:16 AM
  5. Should be simple Query Question
    By brj1 in forum Queries
    Replies: 2
    Last Post: 03-04-2006, 01:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums