jwcolby
jwcolby at colbyconsulting.com
Thu Feb 26 06:56:30 CST 2009
All you have to do is ask. BTW, I discovered that getting a pointer to currentdb is expensive. If you are going to do a lot of dao manipulation of the dao.database object you should get a single pointer and then use that pointer: function dbDao() as dao.database static db as dao.database if db is nothing then set db = currentdb endif set dbdao - db end function The difference when repeatedly calling a function that needs the currentdb pointer can be quite dramatic. John W. Colby www.ColbyConsulting.com William Hindman wrote: > ...we need to get you in RANT mode a lot MORE often ...when you're through > ranting, you make amends with gems like this :) > > William > > -------------------------------------------------- > From: "jwcolby" <jwcolby at colbyconsulting.com> > Sent: Thursday, February 26, 2009 1:13 AM > To: "Access Developers discussion and problem solving" > <accessd at databaseadvisors.com> > Subject: Re: [AccessD] Using Lateral Thinking To solve problems - This time > it is Form Properties > >> Max, >> >>> Couldn't find any way to manipulate custom properties in Forms. Do you >>> know a way? >> Don't say I never did nothing for ya. Happy lateral thinking. >> >> There is this thing in Access called the "documents" collection. >> Documents are something that the >> average joe knows nothing about and so are "well hidden" as I mentioned in >> my previous email. I >> mean they are right there, anyone can find them, anyone can iterate the >> documents collections, the >> properties of a document etc but you have to dig down to that level to >> actually see what is in the >> properties collection. >> >> currentdb.Containers(strContainer).Documents(strDocName) >> >> AFAICT .Containers represents the tabs in an A2003 database. strContainer >> will be the name of some >> tab - Forms, Reports, Queries, Tables, etc. .Documents() contains all of >> the forms, reports etc. >> strDocName would be the name of a specific form, query etc. >> >> AFAICT documents are probably the textual representation of an object, IE >> what you would get if you >> exported the object to a text file. As such it doesn't have to be >> "opened" in design view to >> manipulate, nor "Saved" afterwards. >> >> I haven't done extensive testing to see how many properties you can >> create. I suspect a BUNCH >> however, since these are collections like any other. >> >> To manipulate it: >> >> '--------------------------------------------------------------------------------------- >> ' Procedure : PropertyAdd >> ' Author : jwcolby >> ' Date : 2/26/2009 >> ' Purpose : >> ' >> 'String container can be "Forms", "Reports" etc >> 'strDocName can be the name of any "document" in that container. >> ' >> '--------------------------------------------------------------------------------------- >> ' >> Function PropertyAdd(strContainer As String, strDocName As String, _ >> strPrpName As String, PrpType As DataTypeEnum, varVal >> As Variant) >> Dim db As DAO.Database >> Dim prpNew As Property >> Dim doc As Document >> On Error GoTo Err_PropertyAdd >> >> Set db = CurrentDb >> Set doc = db.Containers(strContainer).Documents(strDocName) >> With doc >> Set prpNew = .CreateProperty(strPrpName, PrpType, varVal) >> .Properties.Append prpNew >> .Properties.Refresh >> End With >> Debug.Print >> db.Containers(strContainer).Documents(strDocName).Properties(strPrpName) >> >> Exit_PropertyAdd: >> On Error Resume Next >> Exit Function >> Err_PropertyAdd: >> Select Case Err >> Case 0 '.insert Errors you wish to ignore here >> Resume Next >> Case Else '.All other errors will trap >> Beep >> MsgBox Err.Description >> Resume Exit_PropertyAdd >> End Select >> Resume 0 '.FOR TROUBLESHOOTING >> End Function >> >> '--------------------------------------------------------------------------------------- >> ' Procedure : PrpGet >> ' Author : jwcolby >> ' Date : 2/26/2009 >> ' Purpose : >> '--------------------------------------------------------------------------------------- >> ' >> Function PrpGet(strContainer As String, strDocName As String, strPrpName >> As String) As Variant >> On Error GoTo Err_PrpGet >> >> PrpGet = >> CurrentDb.Containers(strContainer).Documents(strDocName).Properties(strPrpName) >> >> Exit_PrpGet: >> On Error Resume Next >> Exit Function >> Err_PrpGet: >> Select Case Err >> Case 0 '.insert Errors you wish to ignore here >> Resume Next >> Case Else '.All other errors will trap >> Beep >> MsgBox Err.Description >> Resume Exit_PrpGet >> End Select >> Resume 0 '.FOR TROUBLESHOOTING >> End Function >> >> In the debug window: >> >> >> AddProperty "forms","frmDemoCtls","JWCs test property",dbText,"jwc" >> >> ?PrpGet("forms","frmDemoCtls","jwcs test property") >> jwc >> >> >> Enjoy! >> >> John W. Colby >> www.ColbyConsulting.com >> >> >> Max Wanadoo wrote: >>> Ha! John, Been there. Looked at them yesterday - but I love the fact >>> that >>> you are now also thinking Laterally! >>> >>> Couldn't find any way to manipulate custom properties in Forms. Do you >>> know >>> a way? >>> >>> I could only find custom properties on DB, Tables, Indexes, etc but not >>> forms. >>> >>> Max >>> Laugh more than cry. Smile more than frown. Be generous in spirit. >>> And >>> always stand your round in the pub! >> -- >> AccessD mailing list >> AccessD at databaseadvisors.com >> http://databaseadvisors.com/mailman/listinfo/accessd >> Website: http://www.databaseadvisors.com >> >