Solved

Why onclose event of a form isn't flagging a field as true

Posted on 2013-05-28
7
324 Views
Last Modified: 2013-05-28
I'm trying to figure out why this code isn't flagging a field as true in a separate table.

Private Sub Form_Close()

    If Not IsNull(Me.txtProjectName) Then
        Dim RS As DAO.Recordset
            Set RS = CurrentDb.OpenRecordset("tblProjectNames")
                RS.Edit
                RS!ProjDataAdded = True
                RS.Update
    End If

End Sub
0
Comment
Question by:SteveL13
  • 3
  • 3
7 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39202069
the close event maybe to late to determine the content of control "txtProjectName"

try using the UNLOAD event.

or better, use the Click event of the  button that closes the from.
0
 

Author Comment

by:SteveL13
ID: 39202078
Hmmmm, that didn't work either.
0
 
LVL 9

Expert Comment

by:armchair_scouse
ID: 39202082
Question - is the source field behind txtProjectName in the tblProjectNames table?  If so, not sure why it is not updating, as I have created a dummy form based on tblProjectNames (the table having three fields, ID, ProjDataAdded and ProjectName), and added your Form_Close code.  On adding a value in the Project Name textbox and then closing the form, the Form_Close event code fires successfully and updates the ProjDataAdded field.

Have you tried stepping through the Form_Close event code using a breakpoint?  If so, did it seem to process OK or not?

Just for reference, here's the thing I mocked up (attached).

I agree with Capricorn, might be better to do this update via the code behind a Close button rather than the Form_Close event.


Hope this helps!
Database6.accdb
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39202106
another thing, does the table "tblProjectNames" have only one record?
if not then then you need to limit which record that is need to be edited.
0
 

Author Comment

by:SteveL13
ID: 39202122
Probably is the issue.  tblProjectNames has more than one record..  But I'm not sure how to tell the code which record to edit.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39202149
<But I'm not sure how to tell the code which record to edit. >
what are the fields in the table?

how is this table "tblProjectNames" related to the information in the form that you are closing?
perhaps the content of "txtProjectName"?

in the click of the CLOSE button, place this codes


private btn_CLOSE_Click()
if me.txtProjectName & ""<>"" then

currentdb.execute "Update tblProjectNames set ProjDataAdded=-1 Where  [ProjectName] ='" & me.txtProjectName & "'"


end if
end sub
0
 

Author Comment

by:SteveL13
ID: 39202169
That did it.  Thanks as always!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now