Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513

    can't assign a new value to a form field

    I've got a condition where, when the user has made a duplicate entry in the primary key field of a record entry, i don't want to junk the whole record as being invalid, but flag it as a duplicate field, preserving the remainder of the record entry, and allow the user an opportunity to review the original and then decide how to handle the duplicate value....

    so i wrote this snippet... but i am not able to (and it may be an obvious problem to an experienced programmer -which i am not) re-assign a value to that field (me.type)

    If DCount("[type]", "tbeFixtureTypeDetails", "[type]= '" & Me.Type & "'") > 0 Then
    vmsgtxt = "This fixture type is already being used; please try again"
    vmsgtitle = "DUPLICATE FIXTURE TYPE"
    Response = MsgBox(vmsgtxt, vbCritical + vbRetryCancel, vmsgtitle)
    vType = Me.txtType & "-DUP!"
    Cancel = True
    ' --- this next line in the problem
    Me.txtType = vType
    ' ---
    End If

    any thoughts would be greatly appreciated in advance


    mark

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What is the error message?
    Is vType declared as a string?

    BTW, "Type" is a reserved word in Access and shouldn't be used for object names. In addition, it is not very descriptive.
    See http://allenbrowne.com/AppIssueBadWord.html

  3. #3
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    513
    vType IS declared as a string

    (I know about the "string" reserved thing... unfortunately, I inherited it; and within the project... it's everywhere -ugh)

    but the "type" is actually not giving me a problem (the DCount works just fine);
    the problem is assigning a value to the control txtType... and maybe that's the problem (?) Do I need to assign the value to the field, and not the control (?) ...sounds wrong to me; but hey, learn samething new every day and just maybe ...

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    but the "type" is actually not giving me a problem (the DCount works just fine);
    OK, but at somepoint, it will give you problems. Just be ready for them.

    Without being able to execute the code, it is hard to tell why you can't assign the value to the control.
    Set a break point at the line

    vType = Me.txtType & "-DUP!"

    then single step through the code, looking at the variables. (debug window)
    Check the value of vType, then step down two lines and look at the value for Me.txtType.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You really need to answer ssanfu's question "What is the error message?"

    Also, where do you have this code placed? I suspect that this may be the problem; you cannot, for instance, assign a Value to the txtType Control, with code in the txtType_BeforeUpdate event. Could this be the error message you're receiving?

    "The macro or function set to the BeforeUpdate event or Validation rule Property for this Field is preventing Microsoft Office Access from saving the data in the field."

    I also need to emphasize ssanfu's warning about using Reserved Words as names; sooner or later this is going to bite you in the rump, and this kind of thing can be very difficult to debug!

    Linq ;0)>

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

Similar Threads

  1. Replies: 2
    Last Post: 07-13-2012, 05:12 AM
  2. Replies: 3
    Last Post: 04-23-2012, 12:06 AM
  3. Replies: 3
    Last Post: 03-28-2012, 10:16 AM
  4. Formula to assign a number to a field value?
    By dashingirish in forum Queries
    Replies: 2
    Last Post: 02-23-2012, 01:21 PM
  5. Assign Combo Box from Main form to Subform
    By tbassngal in forum Forms
    Replies: 5
    Last Post: 07-18-2011, 04: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