Results 1 to 12 of 12

Thread: Values not being inserted into table

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Values not being inserted into table

    I'm having a problem with my add() function not inserting rows into my table. I deleted the contents of both the tables it checks so that all the data would be inserted. All the if statements are right, but for some reason it doesn't insert them or give an error message. Any suggestions? Thanks.

    VB Code:
    1. '*ADD()************************************************************************
    2. 'NAME: add()
    3. 'DESC: Adds items that are not currently in the MAIN or ALTER table
    4. Private Sub add()
    5.     On Error Resume Next
    6.    
    7.     Set newConnection = New ADODB.connection
    8.     newConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    9.         "Data Source= C:\Documents and Settings\P6B0438\My Documents\Programs\Visual Basic\DB\Test.mdb"
    10.     newConnection.Open
    11.     Set newRecordSet = New ADODB.recordSet
    12.     newRecordSet.Open "Untitled", newConnection, adOpenKeyset, adLockPessimistic, adCmdTable
    13.    
    14.     Set connection = New ADODB.connection
    15.     connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    16.         "Data Source= C:\Documents and Settings\P6B0438\My Documents\Programs\Visual Basic\DB\cycleCount.mdb"
    17.     connection.Open
    18.     Set recordSet = New ADODB.recordSet
    19.     recordSet.Open "MAIN", connection, adOpenKeyset, adLockPessimistic, adCmdTable
    20.    
    21.     Dim sql As String
    22.    
    23.     newRecordSet.MoveFirst
    24.     Dim num As Integer
    25.        
    26.     Do Until newRecordSet.EOF
    27.         If (inMain(newRecordSet.Fields("PICKSL"), newRecordSet.Fields("SLOT"), newRecordSet.Fields("RES"), newRecordSet.Fields("PROD"), newRecordSet.Fields("PACK"), newRecordSet.Fields("MANU ID"), newRecordSet.Fields("HITIX"), newRecordSet.Fields("PALLET ID"), newRecordSet.Fields("DFP")) = False) Then
    28. MsgBox ("It's not in the MAIN table")
    29.             If (inAlter(newRecordSet.Fields("PICKSL"), newRecordSet.Fields("SLOT"), newRecordSet.Fields("RES"), newRecordSet.Fields("PROD"), newRecordSet.Fields("PACK"), newRecordSet.Fields("MANU ID"), newRecordSet.Fields("HITIX"), newRecordSet.Fields("PALLET ID"), newRecordSet.Fields("DFP")) = False) Then
    30. MsgBox ("It's not in the ALTER table")
    31.                 sql = "Insert into [MAIN] (PICKSL,SLOT,RES,PROD,[DESC],PACK," & _
    32.                     "[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES ('" & _
    33.                     recordSet.Fields("PICKSL") & "','" & recordSet.Fields("SLOT") & _
    34.                     "','" & recordSet.Fields("RES") & "'," & recordSet.Fields("PROD") & _
    35.                     ",'" & recordSet.Fields("DESC") & "','" & recordSet.Fields("PACK") & _
    36.                     "','" & recordSet.Fields("MANU ID") & "','" & recordSet.Fields("HITIX") & _
    37.                     "','" & recordSet.Fields("PALLET ID") & "'," & recordSet.Fields("PALLET QTY") & _
    38.                     ",'" & recordSet.Fields("DFP") & "')"
    39. Debug.Print sql
    40.                 connection.Execute sql
    41. Debug.Print sql
    42. MsgBox ("Should have inserted")
    43.             End If
    44.         End If
    45.        
    46.         newRecordSet.MoveNext
    47.     Loop
    48. End Sub
    49. '*ENDOF*ADD()******************************************************************

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Values not being inserted into table

    Since you are probably getting a runtime error but are ignoring any errors who knows what the problem could be.

    Delete the On Error Resume Next statement.

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Values not being inserted into table

    Looking at your previous thread both the inMain and inAlter procedures use this line of code

    If (rs.RecordCount = 0) Then

    rs.RecordCount could be -1 indicating there are records but ADO does not know how many. This happens when using a ServerSide cursor.

    Change to a Client side cursor or check for EOF

    VB Code:
    1. inMain = Not rs.Recordset.EOF 'if EOF is True return False - ie no record found.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Values not being inserted into table

    Ok sorry about the on error resume next I was testing another part of it. Anyway, I did get an error: Run-time error: '2147217900 (80040e14)' Syntax error in INSERT INTO statement. Thanks.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Values not being inserted into table

    And here's the last couple of lines in the debugger:

    Insert into [MAIN] (PICKSL,SLOT,RES,PROD,[DESC],PACK,[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES ('','','',,'','','','','',,'')
    Insert into [MAIN] (PICKSL,SLOT,RES,PROD,[DESC],PACK,[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES ('','','',,'','','','','',,'')
    SELECT * FROM [MAIN] WHERE [PICKSL]='CA041' and [SLOT]='CA048' and [RES]='3 y F' and [PROD]=292371 and [PACK]='6-14Z' and [MANU ID]='5810806153' and [HITIX]='0241' and [PALLET ID]='0976916' and [DFP]='1'
    SELECT * FROM [MAIN] WHERE [PICKSL]='CA041' and [SLOT]='CA048' and [RES]='3 y F' and [PROD]=292371 and [PACK]='6-14Z' and [MANU ID]='5810806153' and [HITIX]='0241' and [PALLET ID]='0976916' and [DFP]='1'
    SELECT * FROM [ALTER] WHERE [PICKSL]='CA041' and [SLOT]='CA048' and [RES]='3 y F' and [PROD]=292371 and [PACK]='6-14Z' and [MANU ID]='5810806153' and [HITIX]='0241' and [PALLET ID]='0976916' and [DFP]='1'
    SELECT * FROM [ALTER] WHERE [PICKSL]='CA041' and [SLOT]='CA048' and [RES]='3 y F' and [PROD]=292371 and [PACK]='6-14Z' and [MANU ID]='5810806153' and [HITIX]='0241' and [PALLET ID]='0976916' and [DFP]='1'
    Insert into [MAIN] (PICKSL,SLOT,RES,PROD,[DESC],PACK,[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES ('','','',,'','','','','',,'')
    Insert into [MAIN] (PICKSL,SLOT,RES,PROD,[DESC],PACK,[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES ('','','',,'','','','','',,'')
    SELECT * FROM [MAIN] WHERE [PICKSL]='CA020' and [SLOT]='CA040' and [RES]='4' and [PROD]=292611 and [PACK]='6-17Z' and [MANU ID]='71570' and [HITIX]='0241' and [PALLET ID]='0015098' and [DFP]='1'

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Values not being inserted into table

    The Insert statement is loading blank values. Since two of the columns are numeric, but no value is supplied a syntax error occurs.

    Shouldn't the insert statement be created from newRecordset rather than recordset.

    VB Code:
    1. sql = "Insert into [MAIN] (PICKSL,SLOT,RES,PROD,[DESC],PACK," & _
    2.                     "[MANU ID],HITIX, [PALLET ID],[PALLET QTY],DFP) VALUES ('" & _
    3.                     recordSet.Fields("PICKSL") & "','" & recordSet.Fields("SLOT") & _
    4.                     "','" & recordSet.Fields("RES") & "'," & recordSet.Fields("PROD") & _
    5.                     ",'" & recordSet.Fields("DESC") & "','" & recordSet.Fields("PACK") & _
    6.                     "','" & recordSet.Fields("MANU ID") & "','" & recordSet.Fields("HITIX") & _
    7.                     "','" & recordSet.Fields("PALLET ID") & "'," & recordSet.Fields("PALLET QTY") & _
    8.                     ",'" & recordSet.Fields("DFP") & "')"

    Is it even neccessary to open the recordset for the Main table in the Add procedure?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Values not being inserted into table

    Man I've been making some stupid mistakes lately!

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Values not being inserted into table

    Whenever my program is reading files from one database and putting them into another database the program stops responding. Is it really still doing something or has it stopped altogether?

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Values not being inserted into table

    No error is given, and I do not have On Error Resume Next on

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Values not being inserted into table

    Well, you need a DoEvents in the loop to keep your program responding and not hogging CPU cycles.

    Also "Data Source= C:\Documents and Settings\P6B0438\My Documents\Programs\Visual Basic\DB\Test.mdb"

    You should not have your database location in the location you have it in. You should probably use App.Path instead and have your database there or use App.Path & "\DB\" or something of the sort.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Values not being inserted into table

    What exactly does Do Events do?

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  12. #12
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Values not being inserted into table

    DoEvents allows the system to process other events that happen on your system so that it does not appear to freeze.

Posting Permissions

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



Click Here to Expand Forum to Full Width