Page 1 of 2 12 LastLast
Results 1 to 10 of 16

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

  1. #1
    Join Date
    Jul 2005
    Posts
    93
    Rep Power
    0

    Default Primary key[not to repeat]only textvalue in specified txtboxes .etc.

    I have 2 text boxes, txtcode and txtname. txtcode is the primary key .
    txtcode
    1.how can i make sure the value entered in it is not repeated
    2.how can i make sure only textvalues of lenght 6 characters is entered in it.
    txtname
    3. how can i make sure only character and not numbers is entered in txtname
    4.how i can i make the length of character be no more than 15 character.?

    Please remember im using adodc control called "adodc1"

    please help me it is urgent.

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

    Default

    In VC6, I do not use VB6, I would code all of that in a validation function that I set up manually. Then let the function run either when an ok buttton is pressed or when the cursor fucus leaves the text box. If the validition shows an error, I would return the focus to that text box and clear the text box value.

    This may not be the most efficient way, but it will get the job done. I am sure u have acces to the text box data and all previous data that was entered in the program, so it can be coded manually. VB6 is my absolute weakest, but this would be my approach in VC6 or VC#
    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

  3. #3
    Join Date
    Jul 2005
    Posts
    93
    Rep Power
    0

    Default I want to stop my Primary Key from repeating.

    i am buliding a inventory system and i have txtcode as primary key how can i prevent it from repeating so my program dont crash.

    please help
    Last edited by Dj Still; Sep 12, 2005 at 12:54 PM.

  4. #4
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default

    Make sure your primary key is set to "autonumber", this will prevent repeat items in this list. It also means you cannot use a Last_Name or other data for this column.
    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

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

    Default

    Quote Originally Posted by Dj Still
    2.how can i make sure only textvalues of lenght 6 characters is entered in it.
    txtname
    3. how can i make sure only character and not numbers is entered in txtname
    4.how i can i make the length of character be no more than 15 character.?

    Please remember im using adodc control called "adodc1"

    please help me it is urgent.
    'To indicate if the text is invalid
    dim strERROR as string
    strERROR = ""
    'Test the string for length, you could do two separate validations for less 6 and then for greater than 15. But this is a little less typing:
    IF (len(txtname.txt) < 6) OR (len(txtname.txt) > 15) THEN
    strERROR = "NAme must be between 6 and 15 characters."
    ELSE
    'Convert to all uppercase and check for between A and Z, Anything else (numbers and special characters are numerically less than A or greater than Z). - easier than checking for both lower and upper cases.
    IF (UCase(txtname.txt) < "A") OR (UCase(txtname.txt) > "Z") THEN
    strERROR = strERROR & vbcrlf & "Name contains invalid characters."
    END IF
    END IF
    'If there are no errors:
    IF strERROR = "" THEN 'your code to submit info to database.
    The fox was probably right - they could have been sour grapes.

  6. #6
    Join Date
    Jul 2005
    Posts
    93
    Rep Power
    0

    Default

    I Got Ur Coding Cyber Cat

    My Program Is Ok Except For The Primary Key

    My Program Is An Inventory System Where Information On Stocks And Salee Is Made.
    Stock Code Is A Primary Key(by The Name Of Txtcode) How Can I Make Sure The Stock Is Name Repeated.
    If It Is Repeated My Program Will Crash.

    Please Remember I Use Adodc Controls
    My Database Name Is Stocks And My Table Is Stock
    Please Help Its Urgent.

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

    Default

    I'm assuming that you are entering stock details into the application?

    I think your best bet is to read the last stock code from the database table and increase (increment, if its a number) it, then place the new value in the appropriate text box. I would advise disabling the text input on that textbox.

    That way, when you fill out the data, yoy can then add it to your database together with the new code.

    Hope that works for you.
    The fox was probably right - they could have been sour grapes.

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

    Default

    Tell us more about the type of stock you have and what type of data object are in your code, eg recordset. I think you should add a category field if it is permissable, eg. computer stocks have categories of modem, lan, etc.

    Is the problem knowing what kind of stock exists in the database so that the user does not enter a stock that was already there? Otherwise, I will go with cybercat's approach.

    Another approach it to check if the textboxcode exists by SELECT TEXTCODE FROM INVENTORY WHERE TEXTCODE=textboxcode, if something is return then the textcode exists already. Bear in mind that I do not run VB or that control. If it does not exists then add it.
    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

  9. #9
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default

    check to see if the stock code is already exist in the table. if it exists show a error message.

  10. #10
    Join Date
    Jul 2005
    Posts
    93
    Rep Power
    0

    Default

    i was tring to search in the stock code(txtcode) field to see if the exits, if the exit already i would ask the use to enter a number code. but this search is give me problems.

    my field are stock code,stock name, stock cost, stock tax, stock category,stock amount. i use adodc control (adodc1) my database name is stocks and my table is stock.
    this is what i did

    dim sql as string
    dim text as string
    text = txtcode.text

    sql = "select * from stock where [stock code] = ' % " & text & " % ' "
    adodc1.recordsource = sql
    adodc1.refresh

    this is where i stopped.
    i want to put the value in a text box and compared it with txtcode which will match it true.
    then i will ask the use to enter another code.
    well thats about it please.

Posting Permissions

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