Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: I want to stop my Primary Key from repeating.

  1. #11
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Try a break point at this line and then 'step forward' you need to see what sql contains after it executs. Also modify the line to this.
    sql = "select [stock code] from stock where [stock code] = " & txt.code

    'sql may have txt.code if one exist plus other data, or it may be empty if no txt.code exists, not guaranteed
    'then do this (pardon the C++ style)
    if(sql == txt.code)
    'txt.code exist
    else
    'txt.code does not exist
    endif
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  2. #12
    Join Date
    Jul 2005
    Posts
    93
    Rep Power
    0

    Default

    this is wat i did crosswire

    Dim sql As String
    Dim text As String
    text = txtcode.text
    sql = "select [stock code] from stock where [stock code] = '%" & text & "%'"
    If sql = txtcode.text Then
    MsgBox "Stock Code Already Exit"
    Else
    MsgBox "Stock Code Ok"
    End If
    it doesnt work so im woundering if the codeing is correct.

    i think ur way could work

  3. #13
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    if it does not exists in the database then sql may literally equal "no value was found" and if it exists then sql may equal "one row found\ntextbox" MessageBox sql and see
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  4. #14
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    You were correct to have
    sql = "select [stock code] from stock where [stock code] = '%" & text & "%'"
    in principle, but I think there is a syntax error. LIKE is missing with wildcards.

    Syntaxwise,
    sql = "select [stock code] from stock where [stock code] LIKE '%" & text & "%'"
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  5. #15
    Join Date
    Apr 2005
    Posts
    1,333
    Rep Power
    0

    Default

    Dim sql As String
    Dim text As String
    text = txtcode.text
    sql = "select [stock code] from stock where [stock code] = '%" & txtcode.text & "%'"

    adodc1.recordsource = sql
    adodc1.refresh

    If adodc1.[stock code] = txtcode.text Then
    MsgBox "Stock Code Already Exit"
    Else
    MsgBox "Stock Code Ok"
    'submit record
    End If
    The fox was probably right - they could have been sour grapes.

  6. #16
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    I still feel that you need the LIKE or else the wildcards are not recognized as wild cards instead as literals, but it all depends on the data provider and the specific syntax it requires.
    ANALYSIS:
    You can see the use of the percent sign (%) in the statement after LIKE. When used inside a LIKE expression, % is a wildcard.
    http://www8.silversand.net/techdoc/teachsql/ch03.htm
    I have not tested the LIKE yet, but when I do I will correct my assumption
    Last edited by crosswire; Sep 13, 2005 at 06:31 PM.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •