Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2005, 02:10 PM
Authorized User
 
Join Date: Feb 2004
Location: london, uk, United Kingdom.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default subforms problem

hello everyone,

i have a question which is silly but again i am not able to find any answer for it and i know you all have so please help
---------------------------------
autotec
id ->autonumber
and the rest
autotec_kia
id ->autonumber
and the rest
-------------------------------
access VER,2002
ok i have a form with some fields and a subform which will record a some other stuff for my form,normal up to here(form is justified design)which is working perfect

my second form is in datasheet view so i dont have enough space to put my subform here
here is my database

now i just created a button like this
Private Sub history_Click()
On Error GoTo Err_history_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "kia_subsheetdv"

    stLinkCriteria = "[id]=" & Me![id]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_history_Click:
    Exit Sub

Err_Command30_Click:
    MsgBox "There is a problem",,,"Error"
    Resume Exit_history_Click

End Sub

and this is my subform details
this is the record source
SELECT autotec_kia.id, autotec_kia.date, autotec_kia.buying, autotec_kia.selling FROM autotec_kia WHERE (((autotec_kia.id)=Forms!kia_sheet!ID));

ok here is the problem
when i click on the button i can see the history but when i am trying to add anything to it instead of adding it to the current record it will put it somewhere else


and thats it
can any one help



Best Regards,
Hamed Gholamian
 
Old January 27th, 2005, 06:05 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is hard to understand what you have done. Correct me if I am wrong,

You have a Main form containing a subform. This main form has a button on it that opens a seperate form in datahseet view.

The main form's recordsource is set to autotec?
The sub form on the main form's recodsource is set to autotec_kia? (Irrelevant)

The Datasheets recordsource is set to autotec_kia?

The button opens the datasheet form and shows records in autotec kia that relate to the current record on your main form.

How does the table Autotec_Kia relate to the table Autotec? Have you set up relationships between the two tables? In autotec_kia you should have a number field (not the Autonumber field) that acts as a 'foreign key' in order to relate the child record (in autotec_kia) to the parent record (in Autotec).
 
Old January 29th, 2005, 02:09 PM
Authorized User
 
Join Date: Feb 2004
Location: london, uk, United Kingdom.
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello and thanks for your reply
ok the main form use autotec which will record the main details for my products
autotec_kia will record the history of the product such as previous cost and this stuff the subform work fine and if i add anything to subform it will show everything correctly this part is fine so it means my relations are fine
now the second part
i have a form which is in continues form view with a history button in front of every record when i click it will open another form which will give me the history of that product which is again using autotec_kia now if i add anything it will store 0 value in to id field that is my problem

Best Regards,
Hamed Gholamian
 
Old January 31st, 2005, 04:45 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: , , United Kingdom.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It sounds like the Foreign key is not being populated in that form. I guess you havn't enforced relationships between those tables. Have you tried referencing the Main forms ID programaticaly? i.e. create a before insert event on the form that gets the ID from the Main Form -

Private Sub Form_ContinuousView_BeforeInsert()
  me![Foreign_Key] = Forms![Main_Form]![Primary Key]
End sub

Don't forget, if you use this method you will need to run some sort of undo or delete operation if the user Closes or Cancels the entry.

Hope this helps!

Jp




Similar Threads
Thread Thread Starter Forum Replies Last Post
Subforms 150563a Access 1 June 29th, 2007 04:57 AM
subforms ajmil11 Access 2 January 19th, 2006 11:16 PM
transparent subforms Raif Access 3 June 8th, 2004 03:49 PM
Subforms V Access VBA 1 April 21st, 2004 11:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.