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

before update - validating potential new data?

Hi all

i have a textbox [LeBayNum] on a Sub Form [frmllisteditems subform]
bound to a table [tblListedItems]

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 procedure of the textbox
LeBayNUM

On Error GoTo errorhandler
Dim Cnn As ADODB.Connection
Dim Rst As ADODB.Recordset

Set Rst = New ADODB.Recordset
Dim response As Integer

If (Me![LeBayNUM] <> Me![LeBayNUM].OldValue) Or
IsNull(Me![LeBayNUM].OldValue)_ Then
Cnn.Open CurrentProject.Connection
Rst.Open "SELECT * from TblListedItems where [LeBayNUM]= """ &
Me!LeBayNUM &_ """", Cnn, adOpenForwardOnly, adLockReadOnly
If Not Rst.EOF Then
response = MsgBox("Duplicate eBay Number!" & vbCrLf & "Do You want to
Cancel_ the Entry?", vbYesNo + vbCritical, "Duplicate eBay Number")
If response = vbYes Then
[LeBayNUM].Undo
End If
End If
Rst.Close
Set Rst = Nothing
End If
GoTo done
Set Rst = Nothing
GoTo done
errorhandler:
MsgBox Err.Description
done:
End Sub
the error message that i get every time the code is executed is
Object variable or With block variable not set
any help will be appreciated
thank you in advance

Nov 13 '05 #1
1 1427
never mind
i got it
here is the correct version, maybe somebody can use it

On Error GoTo ErrorHandler
Dim Cnn As ADODB.Connection
Dim Rst As ADODB.Recordset
Set Cnn = CurrentProject.Connection
Set Rst = New ADODB.Recordset
Dim response As Integer
If (Me.LeBayNUM <> Me.LeBayNUM.OldValue) Or
IsNull(Me.LeBayNUM.OldValue) Then
Rst.Source = "select * from tbllisteditems where [LeBayNUM]= """ &
Me!LeBayNUM & """"
Rst.Open , Cnn, adOpenForwardOnly, adLockReadOnly, adCmdText
If Not Rst.EOF Then
response = MsgBox("Duplicate eBay Number!" & vbCrLf & "Do you Want to
Cancel the Entry?" & vbCrLf & "If you Click Yes You Will Have to enter
a Different eBay Number" & vbCrLf & "If You Click No, a Duplicate eBay
Number Will be Saved", vbYesNo)
If response = vbYes Then
cancel = True
End If
End If
Rst.Close
End If

Set Rst = Nothing
GoTo done

ErrorHandler:
MsgBox Err.Description
done:
End Sub

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 would like to thank Darryl, he helped me a lot now i have another problem LeBayNum is the primary key in relates to SeBayNum in tblSold relationship is one LeBayNUM to many...
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
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.