G
Guest
Hi there. I have found a few posts with this problem but their solutions did
not work for me.
My DB is for recording the personnel of a ficticious military. I am building
forms for entering all the information. My main form consists of a Tab group
which separates the ifnormation by category. One of the tabs displays the
commendations awarded to a specific soldier/record. the commendations are
displayed as a contiuous subform. Whereas almost all my details for a soldier
is held in one table, the commendation list, with descriptions for what the
commendations are for, and the awarded commendations are in separate tables.
The Commendations table has 5 fields: CommendationName(txt/PK),
CommendationDescription(memo), CommendationMedal(oleObject),
CommendationRibbon(oleObject), and Ribbon(Yes/No). The COmmendationMedal and
CommendationRibbon fileds hold images of what the medal looks like and if it
has an accompanying ribbon, what it looks like too. The ribbon field is used
to determine if the commendation has a ribbon version.
The Awarded Commendations table has 3 fields: RebelID(txt/FK),
Commendation(txt/FK), and CommendationReason(memo). All together is the PK.
This table holds all the soldiers commendations and the reasons for awarding
them.
OK. Now, on the tab with the subform that shows all of a soldier's
commendations there is a command button that is used to add a commendation.
When pressed it opens a new form that has 6 information fields. They are all
unbound. The first is a listbox bound to a query that populates it with all
the available commendations. The next is a textbox that displays the
description of the commendation when it is clicked on in the list box. there
are 2 bound object frames for the images of the selected commendation, a
textbox that holds the RebelID of the current open soldier and a final
textbox that is for entering the reason for awarding the commendation. I
populate all the controls except for the RebelID and Reason for awarding
textboxes with the update event of the listbox. I pass the RebelID to its
textbox when the form is opened.
The user can do the following things in the form: Click on a commendation in
the list box, enter text in the reason for awarding textbox, click the
confirm commendation cmd button, and click the close form cmd button. The
problem I am having is with the code to add the commendation to the awarded
commendations table that is attached to the click event of the confirm
commendation cmd button.
The code I got from Ofer in another thread (thanks!). When I click on the
confirm commendation button I get the error message in the subject line. I
have ensured that the Microsoft DAO 3.6 Object Library is checked in the
references. Here is the code:
Private Sub cmd_confirmcommendation_Click()
On Error GoTo Err_cmd_confirmcommendation_Click
Dim MyDb As Database, Myrec As Recordset
Set MyDb = CodeDb ' Current MDB
Set Myrec = MyDb.OpenRecordset("Select * From AwardedCommendations where
RedelID = " & Me.[txt_id])
Myrec.AddNew
Myrec!RebelID = Me.txt_id
Myrec!Commendation = Me.[lst_commendation]
Myrec!CommendationNotes = Me.[txt_reason]
Myrec.Update
Me.txt_reason = ""
Me.lst_commendation.SetFocus
Exit_cmd_confirmcommendation_Click:
Exit Sub
Err_cmd_confirmcommendation_Click:
MsgBox Err.Description
Resume Exit_cmd_confirmcommendation_Click
End Sub
Thanks in advance for the help.
Damon
not work for me.
My DB is for recording the personnel of a ficticious military. I am building
forms for entering all the information. My main form consists of a Tab group
which separates the ifnormation by category. One of the tabs displays the
commendations awarded to a specific soldier/record. the commendations are
displayed as a contiuous subform. Whereas almost all my details for a soldier
is held in one table, the commendation list, with descriptions for what the
commendations are for, and the awarded commendations are in separate tables.
The Commendations table has 5 fields: CommendationName(txt/PK),
CommendationDescription(memo), CommendationMedal(oleObject),
CommendationRibbon(oleObject), and Ribbon(Yes/No). The COmmendationMedal and
CommendationRibbon fileds hold images of what the medal looks like and if it
has an accompanying ribbon, what it looks like too. The ribbon field is used
to determine if the commendation has a ribbon version.
The Awarded Commendations table has 3 fields: RebelID(txt/FK),
Commendation(txt/FK), and CommendationReason(memo). All together is the PK.
This table holds all the soldiers commendations and the reasons for awarding
them.
OK. Now, on the tab with the subform that shows all of a soldier's
commendations there is a command button that is used to add a commendation.
When pressed it opens a new form that has 6 information fields. They are all
unbound. The first is a listbox bound to a query that populates it with all
the available commendations. The next is a textbox that displays the
description of the commendation when it is clicked on in the list box. there
are 2 bound object frames for the images of the selected commendation, a
textbox that holds the RebelID of the current open soldier and a final
textbox that is for entering the reason for awarding the commendation. I
populate all the controls except for the RebelID and Reason for awarding
textboxes with the update event of the listbox. I pass the RebelID to its
textbox when the form is opened.
The user can do the following things in the form: Click on a commendation in
the list box, enter text in the reason for awarding textbox, click the
confirm commendation cmd button, and click the close form cmd button. The
problem I am having is with the code to add the commendation to the awarded
commendations table that is attached to the click event of the confirm
commendation cmd button.
The code I got from Ofer in another thread (thanks!). When I click on the
confirm commendation button I get the error message in the subject line. I
have ensured that the Microsoft DAO 3.6 Object Library is checked in the
references. Here is the code:
Private Sub cmd_confirmcommendation_Click()
On Error GoTo Err_cmd_confirmcommendation_Click
Dim MyDb As Database, Myrec As Recordset
Set MyDb = CodeDb ' Current MDB
Set Myrec = MyDb.OpenRecordset("Select * From AwardedCommendations where
RedelID = " & Me.[txt_id])
Myrec.AddNew
Myrec!RebelID = Me.txt_id
Myrec!Commendation = Me.[lst_commendation]
Myrec!CommendationNotes = Me.[txt_reason]
Myrec.Update
Me.txt_reason = ""
Me.lst_commendation.SetFocus
Exit_cmd_confirmcommendation_Click:
Exit Sub
Err_cmd_confirmcommendation_Click:
MsgBox Err.Description
Resume Exit_cmd_confirmcommendation_Click
End Sub
Thanks in advance for the help.
Damon