473,569 Members | 2,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem setting tabledef from a form's RecordSource

I'm trying to set a tabledef object from a form object's RecordSource in
Access 97. This is the code:

Public Function EditSubjectForm (ByVal frm As Form) As Boolean

Dim db As Database, tbl As TableDef
Set db = CurrentDb
Set tbl = db!TableDefs(fr m.RecordSource)

END OF CODE

When I run this I get the message "Run-time error '3265'. Item not found
in this collection".

I can display frm.RecordSourc e in the Immediate window, and cut and
paste it there into the following statement which works:

set tbl = db.TableDefs("t blSubjectOSSP")

Does anyone know what I should do to get this to work? Thanks!

Nov 13 '05 #1
3 4970
I've just tested almost identical code in Access 2003 that worked just fine
located in a Standard Module, called from both the Open or Load events of a
Form.

Public Function SetTDF(calledfr om As String, ByVal frm As Form) As Boolean
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set db = CurrentDb
MsgBox calledfrom & " -- " & frm.Name & ": " & frm.RecordSourc e
Set tdf = db.TableDefs(fr m.RecordSource)
MsgBox calledfrom & " -- TableDef is " & tdf.Name
Set tdf = Nothing
Set db = Nothing
SetTDF = True
End Function

The code calling this function in the Form's Module was:

Private Sub Form_Load()
Dim retval As Boolean
retval = SetTDF("Load", Me)
MsgBox "Open SetTDF returned " & retval
End Sub

Private Sub Form_Open(Cance l As Integer)
Dim retval As Boolean
retval = SetTDF("Open", Me)
MsgBox "Open SetTDF returned " & retval
End Sub

So, you are going to need to do some debugging:

Just for "grins", qualify your Database and TableDefs definitions as
DAO.Database and DAO.TableDefs. Next, see if you are really getting what you
expect in the argument "frm", by inserting the following

MsgBox "Form name is " & frm.Name

before you use it. If that looks OK, add similar MsgBox statements to mine
in the code above to see what values you actually have.

The error message you get certainly leads me to believe that you are not
getting a valid table name from "frm.RecordSour ce" when you run your code.

Larry Linson
Microsoft Access MVP

"Bruce Dodds" <br********@com cast.net> wrote in message
news:0JbOc.1797 05$%_6.17383@at tbi_s01...
I'm trying to set a tabledef object from a form object's RecordSource in
Access 97. This is the code:

Public Function EditSubjectForm (ByVal frm As Form) As Boolean

Dim db As Database, tbl As TableDef
Set db = CurrentDb
Set tbl = db!TableDefs(fr m.RecordSource)

END OF CODE

When I run this I get the message "Run-time error '3265'. Item not found
in this collection".

I can display frm.RecordSourc e in the Immediate window, and cut and
paste it there into the following statement which works:

set tbl = db.TableDefs("t blSubjectOSSP")

Does anyone know what I should do to get this to work? Thanks!


Nov 13 '05 #2

"Bruce Dodds" <br********@com cast.net> wrote in message
news:0JbOc.1797 05$%_6.17383@at tbi_s01...
I'm trying to set a tabledef object from a form object's RecordSource in
Access 97. This is the code:

Public Function EditSubjectForm (ByVal frm As Form) As Boolean

Dim db As Database, tbl As TableDef
Set db = CurrentDb
Set tbl = db!TableDefs(fr m.RecordSource)

END OF CODE

When I run this I get the message "Run-time error '3265'. Item not found
in this collection".

I can display frm.RecordSourc e in the Immediate window, and cut and
paste it there into the following statement which works:

set tbl = db.TableDefs("t blSubjectOSSP")

Does anyone know what I should do to get this to work? Thanks!


frm is object no string!

*Sherwood Wang MVP*
Nov 13 '05 #3
Larry Linson wrote:
I've just tested almost identical code in Access 2003 that worked just fine
located in a Standard Module, called from both the Open or Load events of a
Form.

Public Function SetTDF(calledfr om As String, ByVal frm As Form) As Boolean
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set db = CurrentDb
MsgBox calledfrom & " -- " & frm.Name & ": " & frm.RecordSourc e
Set tdf = db.TableDefs(fr m.RecordSource)
MsgBox calledfrom & " -- TableDef is " & tdf.Name
Set tdf = Nothing
Set db = Nothing
SetTDF = True
End Function

The code calling this function in the Form's Module was:

Private Sub Form_Load()
Dim retval As Boolean
retval = SetTDF("Load", Me)
MsgBox "Open SetTDF returned " & retval
End Sub

Private Sub Form_Open(Cance l As Integer)
Dim retval As Boolean
retval = SetTDF("Open", Me)
MsgBox "Open SetTDF returned " & retval
End Sub

So, you are going to need to do some debugging:

Just for "grins", qualify your Database and TableDefs definitions as
DAO.Database and DAO.TableDefs. Next, see if you are really getting what you
expect in the argument "frm", by inserting the following

MsgBox "Form name is " & frm.Name

before you use it. If that looks OK, add similar MsgBox statements to mine
in the code above to see what values you actually have.

The error message you get certainly leads me to believe that you are not
getting a valid table name from "frm.RecordSour ce" when you run your code.

Larry Linson
Microsoft Access MVP

"Bruce Dodds" <br********@com cast.net> wrote in message
news:0JbOc.1797 05$%_6.17383@at tbi_s01...
I'm trying to set a tabledef object from a form object's RecordSource in
Access 97. This is the code:

Public Function EditSubjectForm (ByVal frm As Form) As Boolean

Dim db As Database, tbl As TableDef
Set db = CurrentDb
Set tbl = db!TableDefs(fr m.RecordSource)

END OF CODE

When I run this I get the message "Run-time error '3265'. Item not found
in this collection".

I can display frm.RecordSourc e in the Immediate window, and cut and
paste it there into the following statement which works:

set tbl = db.TableDefs("t blSubjectOSSP")

Does anyone know what I should do to get this to work? Thanks!




Thanks for the tip. I did paste your code into my module, and it ran
fine. It was kind of baffling since it was so similar to my code.

I had been getting inconsistent results with "Compile and Save All" in
this database. Sometimes after running that the menu Compile options
would be greyed out; sometimes not. So I deleted the lines that I posted
above, compacted the database, and retyped the code. Now it works. I
just hope that the database is uncorrupted as it stands - I created it
by importing from a corrupted db.

"O rose, thou art sick . . . "
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2781
by: ColinWard | last post by:
Hi. I use two different pieces of code to manipulate a recordsource for a form. The first one sets the recordsource to null when the form loads. The second is supposed to display the corresponding record when a name is selected from a combobox. ---Code start---- Private Sub Form_Load() If Not Me.FilterOn Then 'If filter is on, then...
4
6985
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which...
11
10237
by: Zlatko Matić | last post by:
Hello. I have a MS Access front-end working with PostgreSQL database. I have successfully created saved File DSN. My paa-through queries are referring to that file as well as linked tables. But I don't understand what will happen when I distribute my front-end to some other PC. How will Access know where is File DSN ? Is there any way that I...
13
4212
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a solution here - until now. This one is driving me crazy. I am making my first attempt at creating a runtime application. I am using Access 2003...
18
18334
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
1
1736
by: Ecohouse | last post by:
I have a main form with two subforms. The second subform has a combo box whose recordsource is set based on a field in the first subform. I tried putting some code in the first subform to do this. This is the code in the Form Current section: strSQL = "SELECT * FROM ModuleComponents WHERE TrainingModuleTopicSK = " &...
9
9674
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
0
1781
by: iceborg | last post by:
Greetings, I have an application that was originally designed in Access 2000. It has been transformed to Access 2002 (XP), Access 2003, and now Access 2007. I have a form and subform, the underlying tables have a one-to-many relationship. The recordsource of both the main form and the subform are set in VBA
1
3544
by: ray2heavy | last post by:
Hey guys, I am getting a "database cant lock table "blah" because it is already in use by another person or process" while trying to delete, then re-populate it. This table is viewed in a subform (CSD appender embedded) in datasheet view, and I have been changing the recordsource of the form to another table, making any changes that are required,...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.