Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 4th, 2004, 12:41 PM
johnde johnde is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sussex UK
Posts: 7 johnde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SubForm #Error when adding a complex PK

Team,

I have been developing a simple access database that records report information. There are two tables. The master and details tables.

In working version of the original version the link between the two tables was just ReportID and the link between the master form and subform was just the ReportID. When a new detail record was prepared, the ReportID was populated in the Subform ready.

The Problem started to happen when I decided that I need to add a BuildingID as well the ReportID in the relationship. I added BuildingID to both Master and detail tables. To ensure the referential integrity I created a PK in the master of RecordID and BuildingID, this is set to be Unique in the Master.

The relationship was changed to link the two fields from the Master table PK to the related fields in the detail table.

The Child and Master links were set to be both RecordID & BuildingID.

When a ReportID and BuildingID combination is selected in the drop down on the detail form. The Master Report information is selected correctly. But when it is tried to created a new Detail record the BuildingID has #Error but the Detail ReportID is correctly populated.

I have tried a wide variety of changes to the PKs in both tables and also the various relationships possible between Master and Subform.

Can anyone tell me what I am doing incorrectly or what changes to the Table / References need to be made ?

Regards,

John de
Attached Files
File Type: zip failing version with reportid & buildingid linked.zip (97.2 KB, 170 views)

Reply With Quote
  #2  
Old January 6th, 2004, 02:25 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
I have had a look at your question, and I might see the problem but I need to check.
I will download your samlpe and investigate.
__________________
BRegs,
TBÁrpi
"I can only show you the door. You're the one who has to walk through it."

Reply With Quote
  #3  
Old January 6th, 2004, 02:45 PM
johnde johnde is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sussex UK
Posts: 7 johnde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks,

If it would help I could upload the working version that only makes use of the ReportID ?

John de

Reply With Quote
  #4  
Old January 7th, 2004, 03:31 AM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
John de,

When a new record is added via the subform, then foreign key in the subform will be automatically filled ONLY if the link is composed by ONE field. Access cannot fill both fields if the foreign key is composed by more than one field. So you need to fill BuildingID from VB code.

Enclosed the database that does this for you.

I simply included a line as the BeforeInsert event handler of your subform called 'AsbestosDataSubMaster'.

When you step to a new record in the subform, the BuildingID field will return #Error, but as soon as you type the first character of the new record the BuildingID field will be filled.

This solution is not the most elegant, but you can use it as a start point.
You can, for example, check if #Error returned, and if yes, then you can set the value of BuildingID.Visible to False in the OnCurrent event of the subform. And, when the first character is typed in a new record, you can set it back to True. Or you can use an unbound field just to hide the field with #Error.

Or, in the OnCurent event, you can check the subform's RecordSet.RecordCount and RecordSet.AbsolutePosition properties. AbsolutePosition is indexed from 0 so when you on the first record then it's 0, when you on the last record, it's RecordCount-1.

Play with it.
Attached Files
File Type: zip johndeok.zip (86.9 KB, 200 views)

Reply With Quote
  #5  
Old January 7th, 2004, 03:35 AM
johnde johnde is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sussex UK
Posts: 7 johnde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for answering the reason why it was not working. I will give it a go later today and let you know if I was successful.

Regards,

John de

Reply With Quote
  #6  
Old January 7th, 2004, 03:41 AM
johnde johnde is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sussex UK
Posts: 7 johnde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Tried you example database and see what you mean. The idea of trapping the #Error as it appears do the same as you have.

Thanks again.

John de

Reply With Quote
  #7  
Old January 7th, 2004, 03:46 PM
johnde johnde is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sussex UK
Posts: 7 johnde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
TBÁrpi,

Thanks for the initial comment about only one field being populated. This helped so much as others had indicated it was a complete change to the db structure !Thanks for the initial comment about only one field being populated. This helped so much as others had indicated it was a complete change to the db structure !

I tried to work on the OnCurrent event and have been able to trap the error and then updated the BuildingID.

This is the code I have created with your original code.

'Private Sub Form_BeforeInsert(Cancel As Integer)
' BuildingID = Forms!asbestosdatamaster.BuildingID1
'End Sub

Private Sub Form_Current()
On Error GoTo Form_error1_err
If Me!BuildingID.Value = "" Then
Me!BuildingID = Forms!asbestosdatamaster.BuildingID1
Else
End If
Form_Exit:
Exit Sub
Form_error1_err:
BuildingID = Forms!asbestosdatamaster.BuildingID1
MsgBox "You are adding a new Record to this report!" 'Err.Description
Resume Form_Exit
End Sub

I would like to add the facility that if the user does not want to add another detail record they can escape and this would go back to the last populated record.

Any thoughts ?

Thanks again a great move forward in my world !

John de

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > SubForm #Error when adding a complex PK


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT