• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

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

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
SteveL13
Asked:
SteveL13
  • 3
  • 3
1 Solution
 
Rey Obrero (Capricorn1)Commented:
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
 
SteveL13Author Commented:
Hmmmm, that didn't work either.
0
 
armchair_scouseCommented:
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
Technology Partners: 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!

 
Rey Obrero (Capricorn1)Commented:
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
 
SteveL13Author Commented:
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
 
Rey Obrero (Capricorn1)Commented:
<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
 
SteveL13Author Commented:
That did it.  Thanks as always!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now