Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a weird one.
    Code that has been running flawlessly for about 4 years now produces the error “Reserved Error”.
    The line of code that returns the error is:
    LinkedFirstName = Nz(Forms![frmSoARisk]![txtLinkedFirstName])
    Where LinkedFirstName is dimensioned as a string.
    The control [txtLinkedFirstName] on form frmSoARisk is a calculated control with this formula.
    =DLookUp("[FirstName]","tblContacts","[ID]=" & Nz([cboLinkedClientID])).
    When the combo box [cboLinkedClientID] has noting selected [LinkedFirstName] should return a zero length string. It has worked beautifully for 4 years, now out of the blue it gives this error for one of my records. It still works just fine for other records. However I cannot see anything that is different in the new record.
    If I enter ? frmSoARisk![cboLinkedClientID] in the immediate window whilst the code is debugged at the error line, I get the error message Run-time error ‘424’ Object required.
    Using Office 2003 and Vista with brand new SP2
    Regards,
    Peter

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

    ? frmSoARisk![cboLinkedClientID]

    you should use

    ? Forms!frmSoARisk![cboLinkedClientID]

    If ID is a number field, you should use

    =DLookUp("[FirstName]","tblContacts","[ID]=" & Nz([cboLinkedClientID],0))

    If ID is a text field, you should use

    =DLookUp("[FirstName]","tblContacts","[ID]=" & Chr(34) & Nz([cboLinkedClientID]) & Chr(34))

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans. The form field is a text field, yet '=DLookUp("[FirstName]","tblContacts","[ID]=" & Chr(34) & Nz([cboLinkedClientID]) & Chr(34))' wouldn't work. I tried '=DLookUp("[FirstName]","tblContacts","[ID]=" & Nz([cboLinkedClientID],0))' and it worked!
    Strange in that the Nz Null replacement defaults to "" or 0 depending on what type of variable is being considered. The variable here is definitely a string, yet putting """" as the replacement didn't work either, while the numerical replacement of 0 did work.
    Even stranger, in the vba code that uses this text field, in the next line of code after where the error occurred the resultant string is tested for it's length [If (Len (str) > 0 then] and this still works. Yet entering ? Len(Nz(0,0)) in the Immediate window returns 1, which would fail my code's test. As I said - strange.
    Attached Images Attached Images
    Regards,
    Peter

Posting Permissions

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