Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 May 22nd, 2006, 01:40 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cazz
Default VBA and forms

hey
i have a form and subform and on the form i have a combo box that u can choose student names from. eventually the form will be to assign reports for extra curricular achievements if i can ever get it workin! i want the subform to display the previous records for the student when chosen in the combo box...does anybody kno how i can do this??

also on the subform i have a button to delete a record but it deletes both the record i want it to delete, and the activity from a different table. im guessin its the relationships, but not completely sure how i can fix it so it only deletes from one table??

i have 3 tables (tblParticipationAwards, tblActivities and tblStudents) the tblParticipation is the many and the others r the one

any help would be great!!

Thanks

caz
 
Old May 22nd, 2006, 10:27 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Are the child and parent fields linked?



mmcdonal
 
Old May 22nd, 2006, 07:06 PM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cazz
Default

thanx 4 the reply!

they werent but now they are but now my subform wont show up in form view...?????
 
Old May 23rd, 2006, 01:59 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cazz
Default

also is there a simple way to lookup values in a text box then delete those values from a record using vba??? Thanks!
 
Old May 23rd, 2006, 06:23 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am not sure about the subform issue. I have never seen that.

What do you want to delete from your records? Do you want to delete from all records, or just a selected record?

mmcdonal
 
Old May 23rd, 2006, 06:40 PM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cazz
Default

just a selected record

in the subform i have a record and then the delete button, so i just want it to get the values from the text boxes in that row and delete them from the table its supposed 2!
 
Old May 24th, 2006, 06:21 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You would do something like:

Create the necessary delete queries to remove the data from the sub tables. They are based on the PK/FK between the parent and child tables.

Create the delete queries, and then add criteria for the FK to get it from your form's PK field:

[Forms]![frmYourFormName].[PKFieldName]

Then when the delete query runs, it will pull the FK from the form and delete those records.

The last thing you want to do is close the form and delete the record currently selected. Then possibly open the form again.

The way you would do this is, before you close the form, take the PK like this:

iPK = Me.PKFieldName

Then pass it to a delete query that does not have a parameter, like this:

sLink = "[PK] = " & iPK ' I am assuming it is a number field

DoCmd.OpenQuery "qryDELETEQueryName", , sLink 'I can't remember the comma position

So all your code would look like:

'-----Code Starts-----

Dim iPK As Integer
Dim sLink As String
Dim sDocName As String

sDocName = "frmMyCurrentFormName"
iPK = Me.PKFieldName
sLink = "[PK] = " & iPK

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDELETEFirstDeleteQuery"
DoCmd.OpenQuery "qryDELETESecondDeleteQuery"
...
DoCmd.Close 'closes the current form
DoCmd.OpenQuery "qryParentDeleteQuery", , sLink
DoCmd.SetWarnings True
DoCmd.OpenForm sDocName, etc

'-----Code Ends-----

I think this covers it...

Any comments anyone?

HTH

mmcdonal
 
Old May 24th, 2006, 08:39 PM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cazz
Default

You are a champion thank you sooooooooooo much!!!!!!
 
Old May 25th, 2006, 06:47 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

De nada amigo.

mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Re : shapes on Excel VBA forms Steve Spies Excel VBA 0 July 23rd, 2007 05:56 PM
Exporting forms from VBA to VB.net Kapil General .NET 0 February 9th, 2007 01:30 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM
VBA Forms (Access 97) timmaher Access VBA 5 September 7th, 2003 05:37 AM





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