3

I'm trying to fix a problem with a MS Access database (.mdb) which I didn't create and it was working fine on another computer which broke, there is a dropdown to select from a value which should fill a table under the dropdown with the result of a query depending on the value selected, the error is a Run-time error:

Method 'Form' of object '_SubForm' failed

So I clicked on debug, and I got a list of if statements that check for the dropdown value:

If dropdown = 1 Then
    Forms!mylist![namelist subform].Form.RecordSource = "SELECT ...  ;"
Else
If dropdown = 2 Then
    Forms!mylist![namelist subform].Form.RecordSource = "SELECT ...  ;"
Else

The error is coming from:

Forms!mylist![namelist subform].Form

I tried to find out the type of the object:

Debug.Print TypeName(Forms!mylist![namelist subform])

it printed SubForm and in the docs there is Form under the SubForm properties, so what could be causing this problem ?

Excuse me if this question is stupid or very easy, but I don't know anything about Visual Basic and everything above I learned today just to fix the problem, so sorry about that.

T think the database is created on MS Access 2003, I tried the database on Access 2003 and 2007 on XP SP3 and Windows 7 and it didn't work, but it worked on Access 2007 on XP SP3 on a computer that I don't have access to anymore.

So what could be causing this problem ? is it a coding problem or am I missing some dependencies ?

Pierre
  • 12,468
  • 6
  • 44
  • 63
  • Are you sure you have the right names ( http://wiki.lessthandot.com/index.php?title=Referring_to_a_control_on_a_subform )? Have you tried a compile? Have you compacted and repaired? Have you decompiled? Sometimes you may need to recreate the form by copying to text and then importing. – Fionnuala Mar 08 '14 at 15:09
  • @Remou the problem is I don't know anything at all about VBA so I don't know how to do what you suggested. – Pierre Mar 08 '14 at 15:15
  • 1
    Half the stuff I suggested was not VBA, for example decompile http://stackoverflow.com/questions/3266542/how-does-one-decompile-and-recompile-a-database-application, compact and repair http://office.microsoft.com/en-ie/access-help/compact-and-repair-an-access-file-HP005187449.aspx – Fionnuala Mar 08 '14 at 15:31
  • Is the database confidential? Can you upload it to a file sharing site? – Fionnuala Mar 08 '14 at 15:41
  • @Remou yes it is, and it's large in size, I'll try to learn how to recreate the form like you suggested, and I'll post back. – Pierre Mar 08 '14 at 15:46
  • 1
    Check out http://www.granite.ab.ca/access/corruption/corruptobjects.htm with reference to `Application.SaveAsText acForm` – Fionnuala Mar 08 '14 at 15:58
  • And do not forget to check for missing references, in the code window go to Tools --> References. You can get very weird errors totally unrelated to the missing reference. – Fionnuala Mar 08 '14 at 17:12
  • @Remou I followed your instructions and found the solution when I tried recreating the form by copying it and I got an error saying something like there are non English characters in the form and it cannot be copied, maybe MS Access doesn't support Unicode, so I changed the system local (language for non-Unicode programs) to the language used in the database and it worked fine, please add an answer and I'll accept it, and thank you. – Pierre Mar 09 '14 at 16:15

2 Answers2

2

When you have a problem with a form, there are various things to check:

Community
  • 1
  • 1
Fionnuala
  • 90,370
  • 7
  • 114
  • 152
1

You should use dot notation here.

And assuming this code runs in the same form, then this should work:

Me.namelist_subform.Form.RecordSource  = "select * from qyCustChild"
Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51