Hi byman2030,
"...if there is a way to do a sort from code ..."
to sort, put this in the code behind your (sub) form:
'~~~~~~~~~~~~~~~~~~~~~~~~
Private Function SortMe()
if me.dirty then me.dirty = false
me.OrderBy = "[fieldname1], ]fieldname2"
me.orderByOn = true
'this will set the recordset to the first record
'and show records in order by the OrderBy clause
me.requery
end function
you can call it on:
form AfterUpdate
form AfterDeleteConfirm
form Load or Open
~~~~~~~~~~~~~~~~
Me is the form in whose code you are behind ...
if you are in a subform, "Me" is the subform and "Me.parent"
is the main form
If you are in the main form, "Me" is the mainform and
"me.subform_controlname.form" is the subform
~~~~~~~~~~~~~~~~
..."currentdb.tabledefs.refresh
[requires dao library reference?..."
I am not sure, though I do not think so... I believe that a
reference to the DAO is only required when you loop through
the collections.
~~~~~~~~~~~~~~~~
"The subform will show new records if I manually do a new sort."
perhaps what you need is
DoEvents
after your Requery
~~~~~~~~
-- DoEvents --
DoEvents is used to make VBA pay attention to what is
currently happening and look to see if the OS (Operating
System) has any requests.
ie: if you have a loop and want to be able to BREAK it with
CTRL-BREAK, put DoEvents into the loop
DoEvents will also update values written to a form by a
general procedure or code behind another form or report
A DoEvents is done when you use MsgBox, or are stepping
through code (since it has to pay attention to the keyboard)
It is a good way to say, "Wake Up!"
~~~~~~~~~~~~~~~~~~~
"is subform_controlname same as subform's name?"
Not exactly. The name that show up for a form in the
database window is what is epcified in the ControlSource for
the subform*... you will have to use the Name property of
the subform in references to it (if the name is ambiguous
such as "Child65", you can, and should, change it to
something meaningful such as the value in the corresponding
ControlSource (ReminderNotesForm).
* me.subform_controlname
refers to the container that the subform is in -- what its
SourceObject is; its Height, Width, Left, and Right
properties; its LinkMasterFields and LinkChildFields; ...
* me.subform_controlname.form
refers to the subform itself -- its Name, Recordset,
Controlname (default collection), etc.
When you design forms, you KNOW if it are going to be a
subform -- (if you are using LinkMasterFields and
LinkChildFields in a subform control to hold it, your link
field controlnames will most likely be Visible=false) and
you can name that accordingly. For instance (and this is my
own notation)
ReminderNotesForm --> fsub_ReminderNotes
Another thing I do to accent the difference between main
forms and subforms is that I capitalize all the letters in a
main form (this makes them easier to spot from the database
window).
ie:
PEOPLE
~~~~~~~~~~~~~~~~
"...I am new to Access2000 but sort of familiar with VB6..."
eMail me and request my VBA chapters... I am writing a book
on programming with VBA ...only have the first few chapters
done, but will be happy to send them to you (and anyone else
who requests).
Warm Regards,
Crystal
Microsoft Access MVP 2006
remote programming and training
strive4peace2006 at yahoo.com
*
Have an awesome day
Hi Crystal,
I'm having a similar problem as Holly.
A subform won't show the new record after I call the requery method. In my
case, however, the recordset type is already set to dynaset.
The subform will show new records if I manually do a new sort. (By the way,
if there is a way to do a sort from code that might solve the problem).
I am using Access2000.
Anyway, I got lost in the code sample and thot you might help clarify. I am
new to Access2000 but sort of familiar with VB6.
I have a main form called StartForm, and the subform is called
ReminderNotesForm (which is based on a table called ReminderNotes).
Here are some questions next to your lines of code.
if me.dirty then me.dirty = false [is "me" my main form or the
subform]
currentdb.tabledefs.refresh [requires dao library
reference?
If so OK I already have done that in this project]
If CurrentProject.AllForms(strFormName).IsLoaded Then [strFormname
=
main form or subfrom?]
If Forms(strFormName).CurrentView <> 0 Then
forms!strFormName!subform_controlname.form.requery [is
subform_controlname same as subform's name?]
Thanks,
byman2030