473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to confirm a record has been written before the code moves on

Currently I have a 3 second loop in place and sometimes that works and sometimes it does not. Here is the problem. The main form is unbound. The reason for this is that I do not want anything writen to the table with out being checked out first. No data is written until the use clicks the 'Save Record' button. The subform is bound to a query that limits the data to 'that' user only. The subform reflects the entries being made by the input on the main form. I have a requery the works 50% of the time. If the user clicks the 'Save Record' it shows up automaticly for them. I want 'EVERY' entry to show up with out them having to hit F5 or something else to get the newest data to show in the subform.

Here is the code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSaveRecord_Click()
  2.   'Make sure date is filled out
  3.     If Nz(txtActivityDate, "") = "" Then
  4.       MsgBox "The Date Field is Required"
  5.       txtActivityDate.SetFocus
  6.       Exit Sub
  7.     End If
  8.  
  9.   ' open connection and recordset
  10.     Dim cnConnection As ADODB.Connection
  11.     Set cnConnection = New ADODB.Connection
  12.     Dim strConnection As String
  13.     strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  14.                     "Data Source=" & CurrentProject.Path & "\metrix_front.mdb;"
  15.     cnConnection.Open strConnection
  16.  
  17.     Dim rsRecordset As ADODB.Recordset
  18.     Set rsRecordset = New ADODB.Recordset
  19.       rsRecordset.CursorType = adOpenDynamic
  20.       rsRecordset.LockType = adLockPessimistic
  21.     rsRecordset.Open "SELECT * FROM tblDailyPlan", cnConnection
  22.  
  23.   'write the new record data to table
  24.     DoCmd.Hourglass True
  25.     rsRecordset.AddNew
  26.       rsRecordset!ActivityDate = txtActivityDate
  27.       rsRecordset!ShipClass_ID = txtShipClass
  28.       rsRecordset!Activities_ID = txtActivity
  29.       If IsNull(Me.txtInputs) Then
  30.         rsRecordset!Inputs = 0
  31.       Else
  32.         rsRecordset!Inputs = txtInputs
  33.       End If
  34.       If IsNull(Me.txtCompletedActions) Then
  35.         rsRecordset!CompletedAct = 0
  36.       Else
  37.         rsRecordset!CompletedAct = txtCompletedActions
  38.       End If
  39.       rsRecordset!ActualTime = txtActualTime
  40.       rsRecordset!Comments = txtComments
  41.       rsRecordset!Employee_ID = [Forms]![frmLogonAssist]![Employee_ID]
  42.     rsRecordset.Update
  43.  
  44.   'clear form and close connections
  45.     Dim ctl As Control
  46.     On Error Resume Next
  47.     For Each ctl In Me.Controls
  48.       ctl.Value = Null
  49.     Next ctl
  50.   'Cleanup
  51.     rsRecordset.Close
  52.     cnConnection.Close
  53.     Set rsRecordset = Nothing
  54.     Set cnConnection = Nothing
  55.  
  56.     txtInputs.Enabled = True 'reactivates control in case "Admin" or "Leave" was selected
  57.     txtCompletedActions.Enabled = True 'reactivates control in case "Admin" or "Leave" was selected
  58.     txtShipClass.Enabled = True 'reactivates control in case "Admin" or "Leave" was selected
  59.  
  60.   ' dont like this but it works - delay is so that recordset can be successfully writen to table before requery runs
  61.     TWait = Time
  62.     TWait = DateAdd("s", 2, TWait)
  63.     Do Until TNow >= TWait
  64.       TNow = Time
  65.     Loop
  66.     DoCmd.Hourglass False
  67.     Forms![frmDailyPlan]![subfrmDailyPlanRange].Form.Requery
  68.     Me.[txtActivityDate].SetFocus
  69. End Sub
Apr 25 '12 #1
8 2016
NeoPa
32,556 Expert Mod 16PB
Bound forms don't give you less control. You just need to use them properly. Unbound forms, on the other hand, are clearly less easy to work with and require you to be very precise about everything you try to do. They're also, generally, less efficient, but that rarely becomes an issue to be fair.

I suggest you take a step back and do it properly with the bound forms approach.
Apr 25 '12 #2
There are arguments on both sides as to the pros and cons to unbound forms. What I have is what I have. Starting over is not an option for me. This goes in to production Monday. The lag is not a show stopper just a minor glitch.
Apr 25 '12 #3
NeoPa
32,556 Expert Mod 16PB
Kaw4Life:
There are arguments on both sides as to the pros and cons to unbound forms.
I'd be interested to see some. I've been in the game for a long while now and never heard anyone with any understanding of the issues recommend unbound forms for managing data. I've seen plenty of it about, but only ever from people who had little idea of the options.

As you say though, this is your project and you have the absolute right to choose your own course. My advice is simply offered as advice. No more.
Apr 25 '12 #4
TheSmileyCoder
2,322 Expert Mod 2GB
I have not before encountered such an issue. As far as I know the code will not run beyond the update point until AFTER the update has finished. I don't know if this could be related to using ADODB type recordsets since I have almost exclusively worked with DAO recordsets which I believe to be preferable when connecting to Access databases.

The only thing I can suspect as a casue could be if your forms recordset is based on a query, which contains a second query, and that Access uses a cached version of the second query. What is the recordsource property of your subform? Or is your subform also unbound?
Apr 26 '12 #5
I did not do the best of jobs describing the enviorment. I am new to this Access stuff, I grew up as a Network type, routers, firewall and stuff like that. I agree that a bound for is far easier to get put together. I was reading Denise Gosnell's book and thought she was saying that unbound is faster and fasilatated multi users better. I have since rebuilt the form in a test copy that is bound. Everthing works well. The only thing that I DO NOT LIKE is that an entry is made to the table just but completing the last field in the form. I am sure I can come up with something the will give the user a more concreat indication that the entry has been made but for now it just happens with little indication it was completed sucessfully. I know I can do a MsgBox but again that slows the process of multipul entries.

To answer your question SmileyCoder the subform is based on a query with no second query. The subform is bound to qryDailyPlanRange. Even when the front and back end are on the same machine I get mixed results when the user makes and entry with the parent unbound form. About 50% of the time the new entry shows up on the subform.
Apr 26 '12 #6
TheSmileyCoder
2,322 Expert Mod 2GB
I must say it sounds weird to me.

If your interested in doing the debugging work, you could try to use a DAO recordset instead and see if that changes anything.


Now when it comes to saving/not saving the record, I personally prefer to write a routine in the forms BeforeUpdate event and add a save button. Quick example:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Private bSaveClicked as boolean
  4.  
  5. Private btn_Save_Click()
  6.   bSaveClicked=True
  7.   On error resume next 'In case user cancels the save
  8.   Docmd.Runcommand accmdSaveRecord
  9.   bSaveClicked=false
  10. End Sub
  11.  
  12.  
  13. Private Sub Form_BeforeUpdate(Cancel as integer)
  14.   'You can put form validation here if you want
  15.  
  16.  
  17.  
  18.   If not bSaveClicked then
  19.     dim intReply as vbMsgBoxResult
  20.     intReply =Msgbox("Do you wish to save this record?",vbyesnoCancel+vbquestion)
  21.  
  22.     Select Case intReply
  23.       Case vbCancel
  24.         Cancel=True
  25.         Me.Undo
  26.       Case vbYes
  27.         Cancel=false
  28.       Case vbNo
  29.         Cancel=true
  30.     End Select  
  31.   Else
  32.    'User clicked save, so don't ask
  33.     Cancel=false
  34.   End if
  35. End Sub
This is just some quick code, which can be refined quite a bit depending on your needs.
Apr 26 '12 #7
One of the things I want is to have the record NOT saved unless they hit 'Save Record'.

I will look at your suggestion and see if I can make that happen.
Apr 26 '12 #8
NeoPa
32,556 Expert Mod 16PB
Kaw4Life:
One of the things I want is to have the record NOT saved unless they hit 'Save Record'.
Indeed. I was going to write some code to illustrate how that can be achieved, but it seems Smiley has done that already. My code would only have been marginally different from that in effect. Somewhat different style maybe, but very similar effect. I'm sure you'll find it helps you to get it working exactly as you wish :-)
Apr 27 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nicola Larosa | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I find the following excerpt fairly sad... (right before the screenshot): "The first version of Scribus used Python, with the Python bindings...
0
by: karenmiddleol | last post by:
The following code works fine I can connect to a SQL database and list all the records in the Orders table onto a web page. Now our users want me to modify it so that each row displayed as a...
3
by: DavidGeorge | last post by:
I have 2 subforms, neither of which is linked to the main form. Of the left of my form is a subform with a list of organisations and on the right is a subform with details of the organisation...
18
by: joshc | last post by:
I've got two bits of code that I would like some more experienced folks to check for conformance to the Standard. I've tried my best to read the standard and search around and I think and hope this...
0
by: Paul H | last post by:
I am using the code below to force a user to confirm changes to a form. This works fine unless the form has a subform. Here is what happens: 1. If I put the code in the both the main form and the...
2
by: Mikus Sleiners | last post by:
I'm trying to write new stream from string and i can't figure out why my memory stream instance is null after i have writen to it with stream writer. Here is an example. MemoryStream stream =...
0
by: paquer | last post by:
Im trying to sort out all subform records except for the new record created via a cmd on the main form. The command creates the new record, autofills some fields, then the PK value is...
0
by: miha.valencic | last post by:
Is there a way (int ASP.NET 1.1 or 2.0) to check which "Cache-Control" headers have been output or set before the page is written to output stream? There is Response.Headers property in .NET...
2
by: thirunavukarasukm | last post by:
Hai.... "i want used confirm in javascript in code behind" i am used confirm button ,,,in code behind. if the confirm button worked the function is return the true...
2
by: gviteri | last post by:
This is my first coding attempt at VBA (6.3) and I'm very ill-rehearsed. I was hoping that someone with more experience would be able to help me out here. This is what I have: Sub Macro1() On...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.