Results 1 to 5 of 5

Thread: DMax (A2K)

  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DMax (A2K)

    Good Afternoon.....

    I struggle with this problem so much, I should know it by heart....

    I want to increase a count by 1 (+1) each time a record is added to the table by SSN.

    I have:
    <hr> SurveyRecord = Nz(DMax("SurveyRecord", "t_Response", "[fkDemoID]" = fkDemoID), 0) + 1
    <hr>
    but it doesn't increase the SurveyRecord value.

    SurveyRecord--Numeric
    fkDemoID--FK--Numeric

    I'm certain it's with the quotes or the lack there of, but if someone could, once again, point this out to me, I would appreciate it.

    Thanks in advance.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

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

    Re: DMax (A2K)

    Where did you put this code?

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DMax (A2K)

    In the OnClick Event of cmdAddNew button.

    Here's the entire code:
    <hr>Private Sub cmdAddNew_Click()
    On Error GoTo Err_cmdAddNew_Click


    DoCmd.GoToRecord , , acNewRec
    fkUserID = DLookup("[pkUserID]", "t_Users", "[UserID]='" & GetUser() & "'")
    SurveyRecord = Nz(DMax("SurveyRecord", "t_Response", "[fkDemoID]" = fkDemoID), 0) + 1


    Exit_cmdAddNew_Click:
    Exit Sub

    Err_cmdAddNew_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddNew_Click
    End Sub
    <hr>
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

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

    Re: DMax (A2K)

    You move to a new record, and set fkUserID (which is a field in the record source, I assume). Unless fkDemoID is an AutoNumber field, it'll be blank at that point. Or am I missing something?

  5. #5
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DMax (A2K)

    Hans,

    I discovered my problem:

    I changed the code:
    <hr> SurveyRecord = Nz(DMax("SurveyRecord", "t_Response", "[fkDemoID] = " & fkDemoID), 0) + 1
    <hr>
    and put the code in the AfterUpdate Event of dSurveyDate and all is well. Thanks for your assistance.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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