A little problem

Results 1 to 3 of 3

Thread: A little problem

  1. #1
    Join Date
    Dec 1969

    Default A little problem

    I have a script that adds a new row to a DB, simple right. But I also have a dropdown menu, its &#060;OPTION&#062; tags are outputted by a DB, well the values for the option tags. <BR><BR>Its just a simple one field table in an access DB. Now every time someone wants to add a new record, they can use the dropdown menu to select an exisiting Part_Kind (thats what the field is) or they can type in a NEW part kind in a simple text field.<BR><BR>Now I need a script that will add a new row to the PartKinds table if they left the dropdown blank, but typed in something for a new PartKind category, BUT if they chose from the drop down, then to do nothing with the Part_Kind Table beacause there is already a row for that PartKind, because it came from a Drop down Menu that was outputted by itself.<BR><BR>Heres my script<BR><BR>Set oConn = Server.CreateObject("ADODB.Connection")<BR> oConn.ConnectionString = "DSN=JeepRecycling"<BR> oConn.Open<BR> <BR> Set oRS = Server.CreateObject("ADODB.Recordset")<BR> oRS.Open "PartKinds", oConn, , adLockOptimistic, adCmdTable<BR> <BR> bolFound = "False"<BR> <BR> Do While Not oRS.EOF<BR> If (StrComp(oRS("PartKind"), sAddKind, vbTextCompare) = 0) Then<BR> bolFound = "True"<BR> Else <BR> oRS.MoveNext<BR> End If<BR> Loop<BR> <BR> If Not bolFound = "True" Then<BR> oRS.AddNew<BR> oRS("PartKind") = KIND<BR> oRS.Update<BR> End If<BR><BR>But it is doing weird things, it adds a new row into the table regardless if the PartKind already exists in the table.<BR><BR>I need help

  2. #2
    Join Date
    Dec 1969

    Default RE: A little problem

    Well, where do you set sAddKind? Are you sure there&#039;s data in there?<BR><BR>Don&#039;t use StrComp(), use =.<BR><BR>What&#039;s with the <BR><BR>bolFound = "false"<BR><BR>???<BR><BR>It&#039;s a string. Set it as a boolean.<BR><BR>It&#039;s less confusing that way... cause If Not bolFound = "True" is highly confusing.

  3. #3
    Join Date
    Dec 1969

    Default UGLY UGLY code, anyway

    Shame on your for using a DO loop to try to find the record!<BR><BR>You should do that using SQL, ONLY!<BR><BR>&#060;%<BR>...<BR>SQL = "SELECT * FROM PartKinds WHERE PartKind = &#039;" & sAddKind & "&#039;"<BR>oRS.Open "PartKinds", oConn, , adLockOptimistic, adCmdTable<BR>If oRS.EOF Then<BR> oRS.AddNew <BR> ...<BR>End If<BR>...<BR>%&#062;<BR>

Posting Permissions

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