 |
| 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
|
|
|
|

May 22nd, 2006, 01:40 AM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 22nd, 2006, 10:27 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Are the child and parent fields linked?
mmcdonal
|
|

May 22nd, 2006, 07:06 PM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanx 4 the reply!
they werent but now they are but now my subform wont show up in form view...?????
|
|

May 23rd, 2006, 01:59 AM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
also is there a simple way to lookup values in a text box then delete those values from a record using vba??? Thanks!
|
|

May 23rd, 2006, 06:23 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|
|

May 23rd, 2006, 06:40 PM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

May 24th, 2006, 06:21 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
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
|
|

May 24th, 2006, 08:39 PM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You are a champion thank you sooooooooooo much!!!!!!
|
|

May 25th, 2006, 06:47 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
De nada amigo.
mmcdonal
|
|
 |