Solved

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

Posted on 2013-05-28
7
345 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access sql to sql server express 10 32
Access 2003 query lost it's only join 7 27
update all email addresses SQL 1 23
Batch Export Reports (with multiple parameters) As PDF 2 21
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

770 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