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

before update - validating potential new data

Hi all

i would like to thank Darryl, he helped me a lot

now i have another problem

LeBayNum is the primary key in [tblListedItems]
relates to SeBayNum in tblSold
relationship is one LeBayNUM to many SeBayNUM

duplicate numbers are not allowed, so
i am trying to bypass access error handling with the following
procedure in the before update event of the textbox LeBayNUM

Private Sub LeBayNUM_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorHandler
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Set Rst = New ADODB.Recordset
Dim Response As Integer
If IsNull(Forms![frmlisted_3]![frmllisteditems
subform].Form![LeBayNUM]) Or Forms![frmlisted_3]![frmllisteditems
subform].Form![LeBayNUM] = " " Then
Response = MsgBox("eBay Number Must be Entered!" & vbCrLf & "Do You
Want to Cancel the Entry?", vbYesNo)
If Response = vbNo Then
Cancel = True
GoTo done
Else
Forms![frmlisted_3]![frmllisteditems
subform].Form![LeBayNUM].Undo
Cancel = True
GoTo done
End If
Else
If (Forms![frmlisted_3]![frmllisteditems subform].Form![LeBayNUM]
<> Forms![frmlisted_3]![frmllisteditems
subform].Form![LeBayNUM].OldValue) Or
IsNull(Forms![frmlisted_3]![frmllisteditems
subform].Form![LeBayNUM].OldValue) Then

Cnn.Open CurrentProject.Connection
Rst.Open "Select [LeBayNUM] from TblListedItems", Cnn,
adOpenForwardOnly, adLockOptimistic

If Not Rst.EOF Then
Response = MsgBox("Duplicate eBay Number!" & vbCrLf & "Do You Want
to Cancel The Entry?", vbYesNo)
If Response = vbYes Then
Forms![frmlisted_3]![frmllisteditems subform].Form![LeBayNUM].Undo
End If
End If
Rst.Close
Set Rst = Nothing
End If
End If

GoTo done

ErrorHandler:
MsgBox Err.Description
done:
End Sub

i cant get i to work
this is the error message:
the database has been placed in a state by user 'admin' on machine
'ibm-a2423412' that prevents it from being opened or locked

Nov 13 '05 #1
1 3536
"gbb0330" <gb*****@gmail.com> wrote
LeBayNum is the primary key in [tblListedItems]
relates to SeBayNum in tblSold
relationship is one LeBayNUM to many SeBayNUM

duplicate numbers are not allowed, so
i am trying to bypass access error handling with the following
procedure in the before update event of the textbox LeBayNUM

the database has been placed in a state by user 'admin' on machine
'ibm-a2423412' that prevents it from being opened or locked

*I think* the problem is that you are attempting to undo the new value, and
use Cancel=True. My own BeforeUpdate events are pretty simple affairs, that
check the value, and if it's not valid, then Cancel=True. No undo.

Now, you've also got this code in ab event associated with LeBayNUM, which
looks like a textbox in a subform. But your code appears to be referencing
the textbox later as Forms![frmlisted_3]![frmllisteditems
subform].Form![LeBayNUM] rather than just Me.LeBayNUM. I really have no
idea what effect that wiould have, but if that is what you are doing, by all
means simplify it.

Try this:

Private Sub LeBayNUM_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrorHandler
Dim Cnn As ADODB.Connection ' Don't use New here
Dim Rst As ADODB.Recordset ' Don't use New here
SetSet Cnn = CurrentProject.Connection ' changed Cnn open
Set Rst = New ADODB.Recordset
Dim Response As Integer

If IsNull(Me.LeBayNUM) Or Me.LeBayNUM = " " Then
Response = MsgBox("eBay Number Must be Entered!" & _
vbCrLf & "Do You Want to Cancel the Entry?", vbYesNo)
If Response = vbYes Then
Cancel = True
End If
Else
If (Me.LeBayNUM] <>Me.LeBayNUM.OldValue) Or _
IsNull(Me.LeBayNUM.OldValue) Then
' Specify Source separately - easier to read
Rst.Source = "Select [LeBayNUM] from TblListedItems"
' Add adCmdText parameter for SQL strings - faster
' Use adCmdTable for tables
' Only need ReadOnly for this - no updates - faster
Rst.Open , Cnn, adOpenForwardOnly, adReadOnly, adCmdText
If Not Rst.EOF Then
Response = MsgBox("Duplicate eBay Number!" & vbCrLf & _
"Do You Want to Cancel The Entry?", vbYesNo)
If Response = vbYes Then
Cancel = True
End If
End If
Rst.Close
End If
End If
Set Rst = Nothing ' needs to be here to always execute
GoTo done
ErrorHandler:
MsgBox Err.Description
done:
End Sub

Darryl Kerkeslager
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PAUL EDWARDS | last post by:
I have a windows form that is bound to a datatable. In VB6 I could just update the field contents and it would be updated in the database, however if I update the text property of the control from...
9
by: Mark | last post by:
Hi there On this page i get some errors when validating: http://www.keyone.nl/lab/beeldlijn/nl/collection.asp The problem is caused by the use of ASP in my pages. This is the code: <a...
1
by: Rolan | last post by:
Having tried various permutations of Before Update and well for that matter, After Update, OnExit, OnEnter, etc. and also Locked controls, I'm still unable to obtain the intended results. There are...
1
by: gbb0330 | last post by:
Hi all i have a textbox on a Sub Form bound to a table i want to make sure there are no duplicate eBay numbers entered in the textbox so here is my code in the before update event...
4
by: Wysiwyg | last post by:
I need to validate a form to ensure that all of the fields add up correctly. I can't do this while the user is entering data since validation needs to be done after the entry is completed. What's...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
5
by: pisquem | last post by:
I have a web applicaiton that has a form that is used to update a record from a sql table. This page will load with a value being retrieved from a querystring. The value is from the querystring...
3
by: rcoco | last post by:
hi, I've tried to update my database using my datagrid but there is no change. here is the code I'm using: private void Update_dataGrid(object source,...
0
by: castlegrpsf | last post by:
I have a win form using VB.NET that needs to set some values prior to updating a SQL database. The values being stored are computed at the time the user is saving the data. It is based on other...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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.