473,406 Members | 2,281 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,406 software developers and data experts.

How to make recordsetclone data always accurate

I have a database with a number of users entering data into an SQL database from a form.

The form is set so that when entering data, if a reference number has already been used the form will display the matching information using recordsetclone.

code is as follows:

Expand|Select|Wrap|Line Numbers
  1.  Dim rs As DAO.Recordset
  2.     Dim ref As String
  3.  
  4.     ref = Me.refrencenumber
  5.  
  6.     Set rs = Me.Recordset.Clone
  7.     rs.FindFirst "[refrencenumber] = '" & Me.refrencenumber & "'"
However the problem is that if the form is left open then the data in the clone does not seem to update itself.

So if more records are entered by others you cannot see this new info without closing the form and then reopening it.

Any ideas on why this is happening and how to fix it?
Mar 9 '11 #1
7 5859
Stewart Ross
2,545 Expert Mod 2GB
Hi. The form's recordsource will need to be requeried, as the recordset is only loaded once, at the time the form is opened. Requerying is straightforward to do:

Expand|Select|Wrap|Line Numbers
  1. Me.Requery
  2. Set rs = Me.Recordset.Clone
This should make sure that the form is up to date before you use the recordset clone method to copy its current source data.

-Stewart

PS if you have any filtering applied to the form you may wish to use its RecordSetClone method, which will reflect the filtered recordset:

Expand|Select|Wrap|Line Numbers
  1. Me.Requery
  2. Set rs = Me.RecordsetClone
Mar 9 '11 #2
I'm getting an error stating that:
The before update or validationrule property for this feild is preventing microsoft office access from saving the data in the field...
Mar 9 '11 #3
Stewart Ross
2,545 Expert Mod 2GB
Ahh, so you have pending updates. Use the form's Dirty property to resolve this:

Expand|Select|Wrap|Line Numbers
  1. IF Me.Dirty Then Me.Dirty = False
  2. Me.Requery 
  3. Set rs = Me.RecordsetClone
The additional line tests the Dirty property and resets it to false, effectively saving the current record being edited.

By the way, if there is a validation error occurring as a result of bespoke code for a Before Update event you will need to resolve that before saving the record using Me.Dirty = False, as otherwise you will get into a position where you can't update the record because the Before Update event has not been completed.

-Stewart
Mar 9 '11 #4
Thanks Stewart, but I'm still getting the same error message.

There are no other events happening as before update and there is no validation rules set for this field.

Any further info would be great thanks.
Mar 9 '11 #5
Stewart Ross
2,545 Expert Mod 2GB
Could you post the whole of the sub or function you are using? If there is no validation or update routine running it suggests that something is being changed by the routine itself, and it would help to see what code you are using.

You could also use trace statements such as

msgbox "Record edited = " & Me.Dirty

to give you an idea of what the status of the current record is at the time your routine is called.

-Stewart
Mar 9 '11 #6
Hi Stewart,

have tried that and get = True

The complete sub is
Expand|Select|Wrap|Line Numbers
  1. Private Sub RefrenceNumber_BeforeUpdate(cancel As Integer)
  2.     On Error GoTo Err_RefrenceNumber_BeforeUpdate
  3.  
  4.     Dim rs As DAO.Recordset
  5.     Dim ref As String
  6.     ref = Me.refrencenumber
  7.  
  8.  
  9.  
  10.     Set rs = Me.Recordset.Clone
  11.     rs.FindFirst "[refrencenumber] = '" & Me.refrencenumber & "'"
  12.     If rs.NoMatch And Me.DepartmentRegistrationNumber Like "*" Then Me.Undo
  13.     If rs.NoMatch And Me.DepartmentRegistrationNumber Like "*" Then MsgBox "This action will result in a record being overwritten! A new request form is being opened to allow you to add the new record. Click ok to reset the form and continue."
  14.     If rs.NoMatch And Me.DepartmentRegistrationNumber Like "*" Then DoCmd.GoToRecord , , acNewRec
  15.  
  16.  
  17.  
  18.     If rs.NoMatch = False Then
  19.         Me.Undo
  20.         Me.Bookmark = rs.Bookmark
  21.         End If
  22.     Set rs = Nothing
  23.  
  24.  
  25.  
  26. Exit_RefrenceNumber_BeforeUpdate:
  27. Exit Sub
  28.  
  29. Err_RefrenceNumber_BeforeUpdate:
  30. MsgBox Err.Description
  31. Resume Exit_RefrenceNumber_BeforeUpdate
  32.  
  33.  
  34. End Sub
Could any other events be causing the same issue other then just the before update?
Mar 10 '11 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi. Your code is running in the Before_Update event of your reference number control. This will itself cause a conflict, because (by definition) the control's update event has not been fired at this stage, and nor has the form's record update event.

I would move the sub to the AfterUpdate event of the same control, if this is the appropriate place to put it, as you will not be able to successfully requery the form or clear the Form Dirty property from the Before Update event of an individual control (because of the clash of events).

The form's dirty property being True when you echo it via the message box just confirms for me that the current record needs to be saved before the requery takes place. This cannot happen until the update event for the current control has completed, hence my suggestion to use its AfterUpdate event property and not its BeforeUpdate one.

-Stewart
Mar 10 '11 #8

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

Similar topics

9
by: PengYu.UT | last post by:
Hi, I write the content of a in file "data" (in Sun Machine). Then I read "data" in both SunOS and linux. But the result is different. Do you know how to make it binary data portable. Best...
1
by: celeluck | last post by:
Is there any way to make them always shown? The VScroll and HScroll seem not working at all. Any one knows why?
14
by: Gidi | last post by:
Hi, For the last week, i'm looking for a way to make a TextBox always write in English (No matter what the OS default language is). i asked here few times but the answers i got didn't help me. i...
2
by: Dave | last post by:
I'm fairly new to this ASPX/OLEDB stuff. I have an OleDbDataReader in one ..aspx page. I do a Server.Transfer to another page. Is it possible to make it so that the data in the OleDbDataReader is...
1
by: Pratchaya | last post by:
Hi, All I want to make transfer data between MySQL Server to MySQL Local . My Environment. Server < --- > My PC Client Server = ::::: MySQL DB Server ( for Linux )
0
by: Henry | last post by:
I am trying to create a TreeView control that works with an ADO Dataset DataTable or the new BindingSource stuff in .NET 2.0 to build a Treeview that is populated. This is what I came up with...
0
by: Ryan Liu | last post by:
Hi, I notice a DataRow in Detached when it is just created by dataTable.NewRow(), and when added to a dataTalbe's row collection, then removed from that collection. For the first situation, I...
5
by: P | last post by:
I was wondering what sort of changes I need to make in order to make an application to be DEP compatible with on Windows XP x64 version 2003. I have compiled an open source C application...
2
by: DubSport | last post by:
I have created a datatable in a function, and it is populated with data. I want to call a new function from an ASP button, and write out some of the values in the datatable, using: string...
1
by: franferns | last post by:
Hi, Im developing this Page And on that Page there s this DIV tag which i want to make it VIsible always that is if its scrolled i would want even to scroll down Similar to AJAX AlwaysVisible...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.