Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

seek method

Posted on 1999-07-30
5
Medium Priority
?
248 Views
Last Modified: 2013-11-26
using the seek method of data_control.recordset,  in the lost_focus event of the text box control, trying to find a dupplicate match when the textbox.datachanged takes effect. but the code I have written does not work in my case.
Any suggestion?   thank you for your time.
0
Comment
Question by:kouroshm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:tmack
ID: 1528631
What version of VB are you running 5 or 6?? And could you show me the code your having trouble with?? ANd lstly are you just trying to locate a duplicate record or is your ultimate goal to elliminate duplicate records??

T
0
 
LVL 3

Accepted Solution

by:
gajendra earned 200 total points
ID: 1528632
Are you using ADO?

Some versions (at least the earlier versions) of the OLE/DB Providers do not support the "seek" method.
0
 

Author Comment

by:kouroshm
ID: 1528633
I'm using VB 6 and ADO,  the textbox control is called, txtpservice and has to be disabled by default unless the add button is true. here is the code:

Private Sub txtpservice_Change()
   If cmdAdd.Value = True Then
     txtpservice.Enabled = True
  End If
   
End Sub

Private Sub txtpservice_LostFocus()
   On Error GoTo errhandler
       Srchcond = txtpservice.DataChanged
       If txtpservice.DataChanged = True Then
           Data1.Recordset.Seek "=", Srchcond
             If Data1.Recordset.NoMatch Then
                Exit Sub
                  Else
                    MsgBox "The product or service code already exists, please enter a unique code.", vbOKOnly, "Duplicate!"
                    txtpservice.Text = ""
                    txtpservice.SetFocus
                    Data1.Recordset.Delete
             End If
        End If
   
   
errhandler:
  Exit Sub
End Sub

0
 
LVL 4

Expert Comment

by:tmack
ID: 1528634
Kouroshm,
Well since gajendra gave and answer this subject it unofficially closed. However there answer is not something I would have accepted and to be quit honestly it is a bit irritating when someone comes in like that and just answers the question(in this case it wasnt even an answer, or at least not an acceptable one).
Anyway if you would like some help I will help. From the looks of your code I would guess your not wanting any duplicate records in that particualr field. Are you using an access datasource? For this example I will assume yes.
What you need to do is set the 'Index' property for that field in Access to 'YES ( No Duplicates)'. This will do all the sekking for you automatically however you will have to trap the error when it occurs. To do that yuo will need to drop some code that looks like this in your procedure.


On error go to Trap


Exit Sub
Trap:
     If Err.Number = 3022 Then   'Duplicate record found  
        MsgBox "Duplicate Record!", vbCritical, "Duplicate Records not allowed!"
        With txtPservice ' Select text and set focus to it.
            .SelStart = 0       'Start at beginnig of the string
            .SelLength = Len(txtPservice.Text) 'Select it
            .SetFocus           'Move focus to it
        End With
     
End If

Anyway this is the REAL stuff so do with it what you want....

T

0
 

Author Comment

by:kouroshm
ID: 1528635
tmack,
I've done what you suggested, some how it works some how it doesn't. it doesn't give you an error about the dupplicate, looks like it will also save it but it actually doesn't in the access data base,  here is the code:

Private Sub txtpservice_Change()
   If cmdAdd.Value = True Then
     txtpservice.Enabled = True
  End If
   
End Sub

Private Sub txtpservice_LostFocus()
   On Error GoTo Trap
    If txtpservice.Text = "" Then
       MsgBox " This filed cannot be Blank, Please enter the product or service code.", vbCritical, "You must enter a value!"
    End If
     'Exit Sub
       
Trap:
  If Err.Number = 3022 Then
      MsgBox "Duplicate REcord!", vbCritical, "Duplicate errors not allowed!"
         With txtpservice
           .SelStart = 0
           .SelLength = (txtpservice.Text)
           .SetFocus
         End With
  End If
  End Sub
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question