Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    mks123's Avatar
    mks123 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    33

    Not sure about the function --MS Access


    Hi frnds,

    Is this custom function which created by user?? the reason I'm trying to figure out ,in one database this below line work but other Database it's not.

    Code:
    CurrentDb.Containers(1).Documents("UserDefined").Properties("Project")

    Regards,
    mks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    they created an object , like a filter, or an object grouping.
    Most likely a group to put all tables/queries as a group in the object filter.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I agree with ranman. It seems they created some object(s) named "UserDefined" with a custom property "Project" to related things into a structure that can accessed and that will persist.

    FYI
    ?CurrentDb.Containers(1).Name
    Databases

    On the database where the code works, what does it produce?

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I don't get what 'works on one computer but not another' means.
    This looks to me like a reference to the built in database property "Properties" but as posted, it doesn't set or get the value. In 2007, you go to the Office button > Mangage > Database Properties > Custom tab. "Project" is one of values in the Name list. I've not seen that syntax before though, so I'm not sure what Containers(1) is.
    The usage might be like
    Code:
    Msgbox CurrentDb.Containers("Databases").Documents("UserDefined").Properties(strPropertyName).Value
    Last edited by Micron; 01-05-2017 at 07:09 PM. Reason: grammar & correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    mks123's Avatar
    mks123 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    33
    thanks for all response.

    Is there anyway to delete exist custom property Or first get all list and then delete.?

    I use below line but it doesn't work.
    db.Containers(1).Documents("UserDefined").Properti es.Delete ("599748")

    does anyone has solution.

  6. #6
    mks123's Avatar
    mks123 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    33
    I have just figured it out. thanks all

    sometime I realized how stupid am I.

  7. #7
    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
    glad you got it sussed! Forum etiquette dictates when a poster resolves their own problem they post the solution, so that others may benefit.

    Linq ;0)>

  8. #8
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I suspect it was along the lines of
    Code:
    CurrentDb.Containers("Databases").Documents("UserDefined").Properties("Project").Value = ""
    mks123 - please do post the solution as suggested
    Thanks.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    And maybe mark this solved???

  10. #10
    mks123's Avatar
    mks123 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    33
    Here we go...

    I had scenario where I have to update "78945" to 78980 and "4" to "5", so I was deleting with below code which is completely wrong.

    With db.Containers(1).Documents("UserDefined").Properti es ''''''Added by Mukesh Yadav
    .Delete ("78945")
    .Delete ("4")
    End With

    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''
    Code:
    Function CreateDbaseProperties()
    Dim db As DAO.Database
    Dim prpNew As Property
    
    
    Set db = CurrentDb
     
    '''' Delete old property  here it is "project" and "Document number.       
    With db.Containers(1).Documents("UserDefined").Properties   ''''''Added by Mukesh Yadav
      .Delete ("Project")
      .Delete ("Document Number")
    End With
    
    
    Set prpNew = db.Containers(1).Documents("UserDefined").CreateProperty("Project", dbText, "78945")  ''''''' you can change "78945" to any number
    db.Containers(1).Documents("UserDefined").Properties.Append prpNew
    Set prpNew = db.Containers(1).Documents("UserDefined").CreateProperty("Document Number", dbText, "4")     '''''' you canchange  "4" to any number
    db.Containers(1).Documents("UserDefined").Properties.Append prpNew
    
    
    End Function

  11. #11
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Why delete properties just so you can recreate them? You change the property value. You don't even have to delete the property value, just change it

  12. #12
    mks123's Avatar
    mks123 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    33
    really... would you like to show me.

  13. #13
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Let's make sure we're on the same page. I mean once you have created a custom property, there's no need to delete it in order to rename it. If you have a situation where you're not sure if a custom or built in property exists or not, the usual approach (for me anyway) is to try to access its value. If you cannot, it generates an error (I forget the error number) so your error trap then creates the property you're trying to access. The end of the trap Resumes, thus whatever you wanted to do after accessing the property gets executed. Typically that is to set the property value. If your code will set it to whatever it already is (assuming there was no error because the property DID exist), then there should be no error in setting its value. This is how I think the routine to set the db ByPassKey property should be attempted - at least that's how I do it.

    Do you need a sample for the BypassKey property setting?

  14. #14
    mks123's Avatar
    mks123 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2014
    Posts
    33
    yes please!!

  15. #15
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    This might help you to get a handle on the documents collection & see what you've got defined. I suggest running this to ensure you haven't deleted anything important:
    Code:
    Sub getDocuments()
    Dim n As Long
    
    'documents collection is zero based, so subtract 1 from the count
    For n = 0 To CurrentDb.Containers("databases").Documents.Count - 1
    Debug.Print CurrentDb.Containers("databases").Documents(n).Name
    Next
    
    End Sub
    The code that follows is how I've done it in the past for the AllowBypassKey property. I suppose you could include the function part within a sub, but for me, when something is going to get called often and has two or more modes, I tend to put it in its own function in a module (library) of functions - helps me to find them as opposed to searching everywhere. Obviously, you would not use the part where the sub manipulates the form, but your own code instead.

    Code:
    Sub SetBypassProp()
    Dim db As DAO.Database
    Dim prop As DAO.Property
    Dim bolMode as Boolean
    
    On Error GoTo errHandler
    Set db = CurrentDb
    Set prop = db.Properties("AllowByPassKey")
    
    'Note to mks123 - in the sample I'm copying from, I get the user level from my user object and if 'admin'
    'I allow this property to cycle, then I change a main form label to red to alert me that it's enabled in case
    'I forget to disable it before releasing a new front end
    If prop = True Then 'bypass enabled; change it to false
       bolMode = False 'pass this change to the function
       prop = apDisableShift(bolMode) 'property value becomes the function value
       DoCmd.SelectObject acForm, "frmSwtchbrd"
       Forms!frmSwtchbrd.lblVersion.ForeColor = RGB(255, 255, 255)
    Else: 'assume prop is false - can only be either true or false
       mode = True 'pass this change to the function
       prop = apDisableShift(bolMode) 'property value becomes the function value
       DoCmd.SelectObject acForm, "frmSwtchbrd"
       Forms!frmSwtchbrd.lblVersion.ForeColor = RGB(255, 0, 0)
    End If
    MsgBox "Enable bypass is now " & prop 'let admin know the property was changed
    
    Set db = Nothing
    Set prop = Nothing
    Exit Sub
    
    errHandler:
    If Err.Number = 3270 Then 'bypass property doesn't exist so create it
       Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False)
       db.Properties.Append prop
       Resume
    End If
    
    End Sub
    Code:
    Function apDisableShift(Mode) As Boolean
    CurrentDb.Properties("AllowByPassKey") = mode
    apDisableShift = mode
    End Function
    Not sure how possible it would be to get stuck in a loop with Resume - never happened to me.
    I'll have to play with the user defined property to see how/if I can use this approach - I'm not familiar with that object model or its error trapping. Will try to post something along that line tomorrow.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access IIf function help
    By drz in forum Access
    Replies: 1
    Last Post: 11-04-2016, 01:29 PM
  2. access qry to vba function
    By slimjen in forum Modules
    Replies: 7
    Last Post: 06-26-2014, 10:03 PM
  3. Using the Nz function (Access 07)
    By jonny3000 in forum Access
    Replies: 5
    Last Post: 11-15-2012, 12:46 PM
  4. function in access
    By ali zaib in forum Access
    Replies: 3
    Last Post: 01-14-2012, 01:09 PM
  5. Help with Access - IIf Function
    By cs93 in forum Programming
    Replies: 7
    Last Post: 03-19-2011, 11:52 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