Solved

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

Posted on 2013-05-28
7
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Query - calculate End of the Month in Query 2 51
Balance after Repayment - 2 6 61
Combo box question 6 53
Cant delete records in query 8 47
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

732 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