It is real common to use me.refresh in a sub of the form. I need to use refresh in function. Instructions says to use form.refresh. But when I put formName.refresh all I get is an error. Can someone please help me.
It is real common to use me.refresh in a sub of the form. I need to use refresh in function. Instructions says to use form.refresh. But when I put formName.refresh all I get is an error. Can someone please help me.
To answer your question isladogs, I right click a area on a calendar and then choose a selection from a list. This puts me in a function where some of the fields are emptied. The form then needs to reflect the changes. I hope this answers your question.
isadogs, the function I mentioned above is in a module.
I would like to know that as well.
You would need to refer to the form by it's full name Forms!FormName.Refresh, however that is then tied to one form, so I assuming you are trying to do something for a few form procedures?
Or pass it it in as an object and use that object reference.
I only ever use functions when I want to return something, else I would use a Sub, to which you can still pass in the form.
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Welshgasman, that worked. I did not know to put Forms! in front of my form name. You mentioned once before about only using functions when a value is returned. Otherwise you use a sub. I write most code on modules. Does it make any difference whether it a sub or a function?
TBH, if you can refer to the form by Form!, what is the point of putting it in a sub/function?
Normally those are used to run a section of code from multiple calls.
As I understand it, a function is there to return a value. Subs do not, though you can do it by passing in by a certain reference method. I stick to subs for common routines. Functions for common routines that need to return a value.
Same applies in Excel, where I use a function to get the last row of a sheet and perhaps a particular column. Then I can use that from anywhere, as I would always forget the syntax.
Code:Public Function GetLastRow(pstrSheet As String, Optional pstrColumn As String) As Long ' Return last used row for sheet and column passed in Dim lngLastRow As Long Dim sht As Worksheet Set sht = Sheets(pstrSheet) If pstrColumn = "" Then pstrColumn = "A" lngLastRow = sht.Cells(ActiveSheet.Rows.Count, pstrColumn).End(xlUp).Row GetLastRow = lngLastRow Set sht = Nothing End Function
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Thank you Welsjgasman for your help & advice. I gonna try to switch
Except that there are places from which you cannot call a sub, so then it has to be a function whether or not you return anything.I only ever use functions when I want to return something, else I would use a Sub
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
True. I have had to done that from the standard switchboard, as it will not run a sub. Then that is just a function that runs a sub. I forgot about that as my memory is not great these days.
Code:Function CreateBackupFE() ' Have to do it this way as Switchboard does not allow parameters. CreateBackup ("FE") End Function Function CreateBackupBE() ' Have to do it this way as Switchboard does not allow parameters. CreateBackup ("BE") End Function
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Also subs cannot be called in queries, only functions
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Not always - yes it returns a value if that is what the function does. The query might do something you would otherwise achieve by looping through a recordset