473,378 Members | 1,411 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,378 software developers and data experts.

vba: how to clear field in datasheet with beforeupdate

6
Hi,

This is the scenario

1 - you have a table with one column: col (stores current date)

2 - you create a form with datasheet default view

3 - for some reason, you want to write a little vba that has the following effects when you press enter key:

a - the entered value never gets into the database
b - the field in the data sheet control is cleared
Expand|Select|Wrap|Line Numbers
  1. Private Sub col_BeforeUpdate(Cancel As Integer)
  2.     Cancel = true;
  3. end sub
  4.  
achieves a), but you have no idea how to achieve b).

Things tried that didn't work (throw errors):
Expand|Select|Wrap|Line Numbers
  1. Me.col = Null
  2. Me.col = Nothing
  3.  

Thank you very much
Sep 4 '15 #1

✓ answered by jforbes

You could try:
Expand|Select|Wrap|Line Numbers
  1. Me.Undo
This will only work for you if you are on a NewRecord, which I'm guessing you are since you have a Cancel=True in the BeforeUpdate Event.

You'll never be able to add more than one row in this scenario. If you plan on filling out multiple rows and then throw them away after you've done what you need to do, you will need to use controls bound to a table, allow the Updates to happen, and then run a DELETE query after you are done to clear out the records.

3 2837
mrijet
64
I m not clear with the question. Cannot help.
Sep 4 '15 #2
jforbes
1,107 Expert 1GB
You could try:
Expand|Select|Wrap|Line Numbers
  1. Me.Undo
This will only work for you if you are on a NewRecord, which I'm guessing you are since you have a Cancel=True in the BeforeUpdate Event.

You'll never be able to add more than one row in this scenario. If you plan on filling out multiple rows and then throw them away after you've done what you need to do, you will need to use controls bound to a table, allow the Updates to happen, and then run a DELETE query after you are done to clear out the records.
Sep 5 '15 #3
zeta
6
@jforbes awesome. your suggestion did the trick. thanks.
Sep 7 '15 #4

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

Similar topics

3
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
2
by: Mark | last post by:
I am attempting to populate several textbox controls from VBA code. With each attempt, I get the following error: "The macro or function set to the BeforeUpdate or ValidationRule property for...
2
by: PC Datasheet | last post by:
In a form/subform I have an unbound combobox in the form header that sets the value of a field in the subform so that it does not have to be entered for each record. In the BeforeUpdate event of...
8
by: p | last post by:
I'm trying to put a query into VBA code and its giving me difficulties. I would like to put the following query: SELECT tbl_Workload.Priority, tbl_Workload.Number AS Num, tbl_Workload.Name,...
1
by: Riun | last post by:
Hi, I'm trying to run an update query in vba and i'ts not working. It does the update but the field is updated to "-1". here's the query: Dim stDocName As String Set rst = New...
3
by: swebster | last post by:
I could use some help to update these functions to only allow the clear and color update on the first onclick and not the second or third etc. Upon entering the site the field includes some...
16
by: rudivs | last post by:
I would like to do data validation in the BeforeUpdate procedure, but Access gives me a runtime error when I try to do this: An example of what I am trying to do is as follows: Private Sub...
7
by: ndhvu | last post by:
Tables: Buy_Header and Buy_Detail. - Buy_Header: info. of each buy (buy_id(PK, auto number), date, shop, bought_by, ...) - Buy_Detail: info. of each item from each buy (buy_detail_id(PK, auto...
1
by: Cerebral 404 | last post by:
I am an amateur programmer and have a form with many input fields (.asp text boxes) that is intended for users to submit personal information: Name, e-mail, phone number, etc. When I began applying...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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: 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...

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.