Recordsource - display problem

  • Thread starter Thread starter Martin Dashper
  • Start date Start date
M

Martin Dashper

I have a bound form which, when the Record Source is hardwired on the
data tab of the form's properties, will display all appropriate
records. However, if I set the Record Source in code eg.
(Me.RecordSource = "myTable"), it only displays the first record.

Any Suggestions?

Martin Dashper
 
Martin, is this form a subform?

If so, you may need to also programmatically clear the subform control's
LinkMasterFields and LinkChildFields properties. When you assign the
RecordSource, Access has a guess and sets these to whatever it feels like.
 
No, it is not a subform, it is a form created by the form wizard (in a
tabular layout) and is opened from another form using
DoCmd.OpenForm.....

Martin
 
I've tried in both 'On Open' and 'On Load'

Dim tableName As String
tableName = "tblDaySheet_Martin2"
Me.RecordSource = tableName

I have also tried the above using the table's name directly without
the intervening variable.

Martin
 
That should work in either of those events. (The Open event would be the
more efficient.)

Something else must be going on. Perhaps the database is corrupt due to a
naming problem generated by Name AutoCorrect. Details:
http://allenbrowne.com/bug-03.html

Or perhaps the VBA is corrupt. Decompile a copy of the database by entering
something like this at the command prompt while Access is not running. It is
all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

Presumably you have already disabled any error handler on this event, so you
are notified of any error.

And presumably ALL the bound controls on the form have an exact matching
field name in this table, and the data types are correct. Access can crash
if bound fields just disappear or change data type.
 
I've tried your method to turn off Name AutoCorrect (new database,
import objects etc) - No Change

I've decompiled the database - No Change

There are no errors displayed.

All bound controls match the table - as I said earlier, if the form's
Record Source property is set to the same table, then it displays
correctly

What is even more confusing is that I have a report which is pretty
much an exact copy of the form layout which has the same line in the
Open event - (Me.RecordSource = tableName) which prints all records
correctly, even when the form which called it does not.

Martin
 
The fact that, when the Record Source is set in code, only one record
is being displayed on the form when there are several records in the
table. Whereas, when the Record Source property for the form is set,
then all records are displayed on the form.

Martin
 
Martin, I meant to ask on what basis you believe there is only one record in
the form. Is it the number shown in the horizontal scrollbar next to the Nav
buttons? Or are you programmatically checking the RecordCount of the form
after assigning the RecordSource?

The RecordCount reports the number of records retrieved so far. Immediately
after reassigning the RecordSource, it will be 1 (if there are any records)
or 0 (if there are none.) Is that what is happening?
 
Sorry. I actually have the Nav buttons turned off, but if I turn them
back on then when the form is only displaying a single record then the
Nav buttons show 'record 1 of 5'... 'record 2 of 5'...etc, so I can
scroll through the records, I just can't see them all at once as I can
when the Record Source property is set.

I'm not sure if I have made the situation entirely clear:

When I set the Record Source in code, the form on the screen displays
only one record, but I can scroll through the other records one at a
time using the Nav buttons.

When, instead, I set the Record Source Property in the forms
properties box then what I see on screen is all 5 records. The nav
buttons still show the correct record numbers.

I don't know how to check the form's RecordCount. It doesn't like
Me.RecordCount

Martin
 
Okay, so the form has multiple records, but is not displaying them all.

You might check its Default View property is set to:
Continuous.
 
Yep, done that. Strangely, if the Record Source property is set on the
form then changing the Default View has the expected effect. However
when I set the Record Source in code it makes no difference if the
Default View is set to Single or Continuous, it just displays one
record.

Martin
 
You have established that the records are present, and that the view is
correct, so I am not sure why they are not showing.

When you change the RecordSource, it will force the records to reload. The
form will therefore be at the first record, so if the view is correct, the
other records should be displayed unless there is a filter, ServerFilter, a
bad index, or some other issue that is fowling up the loading of the
records.

I think I am out of suggestions. If anyone else has some, please add them.
 
Success!
Thanks for all your help, but I seem to have finally solved, or at
least worked around, the problem by turning off the Auto Resize
property.

Martin
 
Back
Top