473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Freaky (:S) insert "errors"

65
Hi,

I've got a table called Aerosol and a table called LinkTabel.

Now I do an update to a table from an excell sheet, this table is called ExportAerosol. So far so good, the import works perfect.

Now when I want to transfer the data from the ExportAerosol table to the Aerosol table I have to make a unique key. I do this by adding a string to another key. Now there is no problem when I update the Aerosol table. It adds the values I wanted (presumed) normally. But It (for some reason) adds only a part to the link table.
E.g. I add 41 records to my Aerosol table trough a loop, in the same loop I add records to LinkTabel to. But this gives only 33 records.

This is when the link between the two tables (unikey) isn't layed (one on one).

When I lay this link it adds 33 records to LinkTabel but none to Aerosol.

I want to add an equal amount of records to both tables.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Function BuildImport()
  2.     Dim key As String
  3.     Dim datum As String
  4.     Dim gestart As Date
  5.     Dim gestop As Date
  6.  
  7.  On Error GoTo BuildImport_Err
  8.     Dim db As Database
  9.     Dim rst As Recordset
  10.     Dim i As Integer
  11.  
  12.     Set db = CurrentDb
  13.     Set rst = db.OpenRecordset("SELECT * FROM ExportAerosol WHERE omit = 'i';")
  14.     Do Until rst.EOF
  15.         i = i + 1
  16.  
  17.         gestart = #1/1/9999#
  18.         gestopt = #1/1/9999#
  19.         If Not (rst.Fields(13).Value = "") Then
  20.             gestart = rst.Fields(13).Value
  21.         End If
  22.         If Not (rst.Fields(14).Value = "") Then
  23.             gestopt = rst.Fields(14).Value
  24.         End If
  25.  
  26.         datum = Mid(rst.Fields(5).Value, 1, 10)
  27.         datum = DateFunctions.dateFormat(datum)
  28.         key = "aer" & rst.Fields(0).Value
  29.         db.Execute "INSERT INTO LinkTabel (unikey, eadnr, datum) VALUES ('" & key & "'," & rst.Fields(3).Value & ",#" & datum & "#);"
  30.         db.Execute "INSERT INTO Aerosol (dkey, eadnr, eersteZendtijd, VerslagNr, cnr, TypeToestel, Hulpstuk, Medicatie, Frequentie, Onderhoud, Start, Stop, unikey ) VALUES(" & rst.Fields(0).Value & "," & rst.Fields(3).Value & ",'" & rst.Fields(5).Value & "'," & rst.Fields(7).Value & "," & rst.Fields(6).Value & ",'" & rst.Fields(8).Value & "','" & rst.Fields(9).Value & "','" & rst.Fields(10).Value & "','" & rst.Fields(11).Value & "','" & rst.Fields(12).Value & "',#" & gestart & "#,#" & gestopt & "#,'" & key & "');"
  31.  
  32.         rst.MoveNext
  33.     Loop
  34.     Debug.Print i
  35.  
  36. BuildImport_Exit:
  37.     Set rst = Nothing
  38.     Set db = Nothing
  39.     Exit Function
  40.  
  41. BuildImport_Err:
  42.     MsgBox Error$
  43.     Resume BuildImport_Exit
  44. End Function
Please help me :D
(got to finish this today :s)

Greetz
Twanne
Aug 2 '07 #1
3 1675
Twanne
65
Could somebody please help me??? I really need this done, but I have no idea where things go wrong.
Aug 2 '07 #2
ADezii
8,834 Expert 8TB
Hi,

I've got a table called Aerosol and a table called LinkTabel.

Now I do an update to a table from an excell sheet, this table is called ExportAerosol. So far so good, the import works perfect.

Now when I want to transfer the data from the ExportAerosol table to the Aerosol table I have to make a unique key. I do this by adding a string to another key. Now there is no problem when I update the Aerosol table. It adds the values I wanted (presumed) normally. But It (for some reason) adds only a part to the link table.
E.g. I add 41 records to my Aerosol table trough a loop, in the same loop I add records to LinkTabel to. But this gives only 33 records.

This is when the link between the two tables (unikey) isn't layed (one on one).

When I lay this link it adds 33 records to LinkTabel but none to Aerosol.

I want to add an equal amount of records to both tables.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Function BuildImport()
  2.     Dim key As String
  3.     Dim datum As String
  4.     Dim gestart As Date
  5.     Dim gestop As Date
  6.  
  7.  On Error GoTo BuildImport_Err
  8.     Dim db As Database
  9.     Dim rst As Recordset
  10.     Dim i As Integer
  11.  
  12.     Set db = CurrentDb
  13.     Set rst = db.OpenRecordset("SELECT * FROM ExportAerosol WHERE omit = 'i';")
  14.     Do Until rst.EOF
  15.         i = i + 1
  16.  
  17.         gestart = #1/1/9999#
  18.         gestopt = #1/1/9999#
  19.         If Not (rst.Fields(13).Value = "") Then
  20.             gestart = rst.Fields(13).Value
  21.         End If
  22.         If Not (rst.Fields(14).Value = "") Then
  23.             gestopt = rst.Fields(14).Value
  24.         End If
  25.  
  26.         datum = Mid(rst.Fields(5).Value, 1, 10)
  27.         datum = DateFunctions.dateFormat(datum)
  28.         key = "aer" & rst.Fields(0).Value
  29.         db.Execute "INSERT INTO LinkTabel (unikey, eadnr, datum) VALUES ('" & key & "'," & rst.Fields(3).Value & ",#" & datum & "#);"
  30.         db.Execute "INSERT INTO Aerosol (dkey, eadnr, eersteZendtijd, VerslagNr, cnr, TypeToestel, Hulpstuk, Medicatie, Frequentie, Onderhoud, Start, Stop, unikey ) VALUES(" & rst.Fields(0).Value & "," & rst.Fields(3).Value & ",'" & rst.Fields(5).Value & "'," & rst.Fields(7).Value & "," & rst.Fields(6).Value & ",'" & rst.Fields(8).Value & "','" & rst.Fields(9).Value & "','" & rst.Fields(10).Value & "','" & rst.Fields(11).Value & "','" & rst.Fields(12).Value & "',#" & gestart & "#,#" & gestopt & "#,'" & key & "');"
  31.  
  32.         rst.MoveNext
  33.     Loop
  34.     Debug.Print i
  35.  
  36. BuildImport_Exit:
  37.     Set rst = Nothing
  38.     Set db = Nothing
  39.     Exit Function
  40.  
  41. BuildImport_Err:
  42.     MsgBox Error$
  43.     Resume BuildImport_Exit
  44. End Function
Please help me :D
(got to finish this today :s)

Greetz
Twanne
  1. In Line #10 you are declaring i as an Integer.
    Expand|Select|Wrap|Line Numbers
    1. Dim i As Integer
  2. In Line #13, you are using i as a String by Delimiting it in while creating the Recordset.
    Expand|Select|Wrap|Line Numbers
    1. Set rst = db.OpenRecordset("SELECT * FROM ExportAerosol WHERE omit = 'i';")
    At this point i has not been initialized and has a value of 0 - are you aware of this? If you are and this is your intention, they try:
    Expand|Select|Wrap|Line Numbers
    1. Set rst = db.OpenRecordset("SELECT * FROM ExportAerosol WHERE omit = " & i ";")
Aug 7 '07 #3
ADezii
8,834 Expert 8TB
Could somebody please help me??? I really need this done, but I have no idea where things go wrong.
  1. In Line #10 you are declaring i as an Integer.
    Expand|Select|Wrap|Line Numbers
    1. Dim i As Integer
  2. In Line #13, you are using i as a String by Delimiting it in while creating the Recordset.
    Expand|Select|Wrap|Line Numbers
    1. Set rst = db.OpenRecordset("SELECT * FROM ExportAerosol WHERE omit = 'i';")
  3. At this point i has not been initialized and has a value of 0 - are you aware of this? If you are and this is your intention, they try:
    Expand|Select|Wrap|Line Numbers
    1. Set rst = db.OpenRecordset("SELECT * FROM ExportAerosol WHERE omit = " & i & ";")
    which would be the same as
    Expand|Select|Wrap|Line Numbers
    1. Set rst = db.OpenRecordset("SELECT * FROM ExportAerosol WHERE omit = " & 0 ";")
Aug 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Coral Snake | last post by:
I am having problems with programming even simple "Hello World" programs from books and tutorials that use Python GUI libraries. Such Programs cause python to throw "Attribute Errors" even when the...
5
by: Michelle Kinsey-Clinton | last post by:
Hello, I am writing an ASP app which is giving me some very frustrating errors. They appear intermittently, no real pattern to them, and often go away if you reload, or back up a few pages and...
2
by: George Hester | last post by:
with Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp. My other...
0
by: Henry | last post by:
Hi, I have cases where I connect to the web site and MySQL is not working : Message : "Too many connection errors", Unblock with 'mysqladmin flush-hosts'. What I did is a script that check...
1
by: Robert Oschler | last post by:
How can I get "parse" errors, not runtime errors, output to a log file of my choice (and preferably in a format I can choose)? I'm running PHP4. Thanks.
1
by: Derek | last post by:
I am writing a web application for job seekers, and am adding a section that allows administrators to upload jobs to the system via xml. I have used an xml schema to validate the xml they upload....
0
by: Steve Franks | last post by:
When I compile my application if there are any .net coding errors they show up fine in the error list in VS.NET 2005 following my attempt to compile. However there are also a ton of other errors...
7
by: iKiLL | last post by:
Hi all I am still pretty new to .Net and C#. I have come from a VB6 Background.
0
by: Gregory Gadow | last post by:
We have a number of development machines in our IT department, all running the same version of VS 2005 sp 1. Our company website and several compiled components were all written in VB.Net 2.0 using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.