Results 1 to 6 of 6
  1. #1
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125

    Criteria Increment problem

    I'm not exactly sure why this isn't incrementing because it seems to be working in a similar situation elsewhere.

    Code:
    Dim dbCMC As DAO.Database
    Dim strSQL As String
    Dim lngChgNum As Long
    Dim datChgDate As Date
    datChgDate = Date
    lngChgNum = DCount("JobNum", "dbo_tblWgtTrack", "[JobNum] = '" & Me.txtJobNum & "' And [Detlr] = '" & Me.cboDtlr & "' And [Segment] = '" & Me.txtSegment & "' And [Desc] = '" & Me.txtDesc & "'")
    lngChgNum = lngChgNum + 1
        Set dbCMC = CurrentDb
        strSQL = "INSERT INTO dbo_tblWgtTrack([DetDBID], [JobNum], [Detlr], [Segment], [Desc], [ChgNum], [ChgDate], [DetWgt], [Reason]) " & _
        "VALUES('" & strDetDBID & "', '" & Me.txtJobNum.value & "', '" & strEmpName & "', '" & Me.txtSegment.value & "', '" & Me.txtDesc.value & "', " & lngChgNum & ", #" & datChgDate & "#, '" & Me.txtDetWt.value & "', '" & "Revision" & "')"
    It's supposed to run every time the weight is updated, so that if there are any other entries it logs the current weight and what change number it is (based on previous logged changes for that submittal)

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,740
    Do you get an error message?
    You could use some debug.print statements to see the values.
    What event drives this code?

  3. #3
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Sorry, don't get an error message, the code mostly works fine, it just doesn't increment for some reason. I did a debug on both the insert string and just the lngChgNum variable and both cases the actual entry was fine, but it just enters a "1", instead of adding a 1 to whatever count it is supposed to produce.

    It runs on the AfterUpdate of entering the weight (as an update).

  4. #4
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Sorry, there was an inaccurate value, it just wasn't where I was expecting it kind of. There was a mismatch between the DCount and Insert statements in the Detailer's name. It's working now, thanks.

  5. #5
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    A side not: I switched to the DMax function instead of DCount, it might be a bit more efficient I figured.

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,740
    Yes, DCount gets you the count of entries with criteria
    DMax gives you the value

    so Dmax +1 would be the next value.

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

Similar Threads

  1. Replies: 5
    Last Post: 11-12-2010, 12:10 PM
  2. Query Criteria problem
    By wpdesigner in forum Queries
    Replies: 0
    Last Post: 07-07-2010, 09:10 AM
  3. Replies: 1
    Last Post: 05-05-2010, 01:54 AM
  4. Replies: 1
    Last Post: 03-29-2010, 10:23 AM
  5. Replies: 3
    Last Post: 06-03-2009, 07:15 AM

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