Solved

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

Posted on 2013-05-28
7
334 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…

867 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

16 Experts available now in Live!

Get 1:1 Help Now