#name? (1 Viewer)

LOUISBUHAGIAR54

Registered User.
Local time
Yesterday, 22:26
Joined
Mar 14, 2010
Messages
157
I have a subform on a form. The form is unbound and has several controls on it including a listbox, other than the subform. On double clicking the listbox a new record is added on the subform using vba.

I have programmed the event procedure to be able to focus on the new record in the subform as soon as it is added.

The problem is this. To track down the new item I am using the ID as reference. This is the autonumber. When I open the subform independently (not within the form) the ID field shows the ID number correctly. However when the form is opened with the subform within, the ID field does not show the ID number but shows #NAME?.

Does anyone know why this is happening ?
 

JHB

Have been here a while
Local time
Today, 07:26
Joined
Jun 17, 2012
Messages
7,732
Do you remember to requery the subform after the new record is added?
Show the code you use!
 

LOUISBUHAGIAR54

Registered User.
Local time
Yesterday, 22:26
Joined
Mar 14, 2010
Messages
157
Many thanks for your response. I do not think the problem is with the code. I do requery the subform after adding the new record. The problem lies with the fact that in the subform the ID field only shows #NAME?. As such the code cannot track down the new record just added.

The strange thing is that when opened independantly of its form the subform shows all the ID autonumbers as expected. As far as i can see there lies no ambiquity with the ID as there is no reference to another one from a different table or query. Thanks for your input.
 

Minty

AWF VIP
Local time
Today, 06:26
Joined
Jul 26, 2013
Messages
10,371
Is there any reference to Master and Child fields in the sub-form container? If the main form is completely unbound there probably shouldn't be.
If you are storing the new record id in the main form to make it display in the sub form then there should be.
Is the sub form set to allow edits, or data entry ?
 

jdraw

Super Moderator
Staff member
Local time
Today, 01:26
Joined
Jan 23, 2006
Messages
15,379
Is it possible that you are using/referencing a field in a table that is a Lookup field?

From the message you are receiving, it seems Access doesn't know the "field" -- either it has not been defined or has not been set up properly... If you have linked Master/Child correctly; no spelling errors; then I would try some debug.print statements and/or step debugging to track down the issue.
Good luck.
 

LOUISBUHAGIAR54

Registered User.
Local time
Yesterday, 22:26
Joined
Mar 14, 2010
Messages
157
Hi. The main form is unbound and there are no parent/child links. The code works well and a new record is added and one can scroll down to it. It is this last step I wanted to automate. However the only way to get to this new specific recorc is to use the FINDRECORD method using the ID field.

I cant understand why the ID numbers cannot turn up on the subform within the form. .... Thanks.
 

jdraw

Super Moderator
Staff member
Local time
Today, 01:26
Joined
Jan 23, 2006
Messages
15,379
Seems a subform is only a subform to a form, if there is some linking/connecting set up.
May be some info here.
 

JHB

Have been here a while
Local time
Today, 07:26
Joined
Jun 17, 2012
Messages
7,732
Post your database with some sample data, (zip it) + info how to reproduce the fault you get.
 

LOUISBUHAGIAR54

Registered User.
Local time
Yesterday, 22:26
Joined
Mar 14, 2010
Messages
157
Problem solved.. At Last.

The subform had a query in its record source. However it had its recordsource changed with vba as part of the workings of the main form. Now I realised that while the ID field was included in the query in the permanent record source of the subform, the ID was not included in the SQL statement in the vba code.

I included it and now the code is working like a song. Thanks for your support and co-operation.
 

jdraw

Super Moderator
Staff member
Local time
Today, 01:26
Joined
Jan 23, 2006
Messages
15,379
Good debugging, and thanks for telling us the solution.
Good luck with your project.
 

Users who are viewing this thread

Top Bottom