Really need some help with VBA SQL (1 Viewer)

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
The situation is:
1 tble called Assembly from this is a main form called Assembly
1 tble called Assembly details from this a sub form called Assembly Details on the main form called Assembly.

The main for just has a few cells for entry but one of them is an autonumber that I have created plus one type thing.

The designer wants to enter some brief information into the main form in order to get an autonumber as the next number for their drawings. They will then go and do as they want with it and later an excel sheet is created from 2 other cad programs. I upload the excel to access and have coded this and it works.

So now I have it sitting in access as a 'temp table' but what I need to do is now give it a code to upload it to the assembly details form against the correct auto number.

What I have managed to code so far is to upload excel to access 2010 and to be able to upload it to the Assembly Details tbl however, it adds it underneath the last entry but not against the appropriate autonumber i.e sub form and not showing on the sub form. What I want it to do is for the code to recognise the autonumber in the main form find it on the subform and load all the rows not just the row with the matching number the matching number will be on the first row under the headings of the excel sheet that has been uploaded as a table.

This is what I have so far:

Option Compare Database
Option Explicit
Private Sub cmdOK_Click()
'-- Declare some useful variables
Dim StrFileName As String
Dim StrTableName As String
Dim StrSQL_rptImportAssembly As String
Dim StrSQL_rptBillofMaterials As String
Dim StrSQL_Append1 As String

'-- Read the file and user names entered by the user into the text boxes
StrFileName = Me.txtFileName
StrTableName = Me.txtUserName

'-- Link the spreadsheet to Access
DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel12Xml, Me.txtUserName, "C:\LinkExcel\" & Me.txtFileName, True
'-- Append some data
DoCmd.SetWarnings False
StrSQL_Append1 = "INSERT INTO tblAssemblyDetails (ItemNumber,Quantity,PartNumberId,Drawing,PartNumberDescription,Material,Supplier,Length,WidthOD,ThickID,Finish)SELECT Item,Qty,PartNumber,Drawing,Description,Material,Supplier,Length,Width_OD,Thickness_ID,Finish FROM " & StrTableName
DoCmd.RunSQL StrSQL_Append1

'-- Finally, remove the linked table (note that this just deletes the link, the spreadsheet file is not actually deleted)
DoCmd.DeleteObject acTable, StrTableName
'-- Give feedback to the user
MsgBox "Operation completed"
End Sub

Please help:banghead:
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
So now I have it sitting in access as a 'temp table' but what I need to do is now give it a code to upload it to the assembly details form against the correct auto number.

For this bit you will need to open a cursor against the temp table, (SELECT all of the cols), loop through one-by-one, test for the existence of the audonumber ID record against the target table, if exists then UPDATE, if not exist then INSERT.

I do this sort of thing using an ADO.Recordset object defined at Class level so that the adoRS object survives as the class methods interact with each other. I do not believe I have pasted code for such in this forum already, so I will post here:

Code:
Option Compare Database
Option Explicit

'Other class attributes not DB table related
Dim strFETempTableName As String
Private adoRStt As Object
Dim ObjBEDBTbl As Object

'Attributes for standard pick list table
Public aid As Long
Public authid As Integer
'This field is display only in the FE tmptbl
Public authusername As String
Public logtimestamp As String
Public id As Integer
Public sort As Integer
Public active As Boolean
Public title As String

Private Sub Class_Initialize()

  'And clear the class attributes
  Me.Clear

End Sub

Private Sub Class_Terminate()
On Error GoTo Err_Terminate

  Set adoRStt = Nothing
  Set ObjBEDBTbl = Nothing

Exit_Terminate:
  Exit Sub

Err_Terminate:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardTbl, Subroutine: Class_Terminate()")
  Resume Exit_Terminate

End Sub

'This is a generic API that clears all of the field attributes
Public Sub Clear()
On Error GoTo Err_Clear

  Me.aid = 0

  Me.authid = 0
  'This field is display only in the FE temp table
  Me.authusername = vbNullString

  Me.logtimestamp = vbNullString
  Me.id = 0
  Me.sort = 0
  Me.active = False
  Me.title = vbNullString

  strFETempTableName = vbNullString

Exit_Clear:
  Exit Sub

Err_Clear:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardTbl, Subroutine: Clear()")
  'Disable further error handling. Since the code was already handling an error, if we raised the error without first
  'turning it off, that would result in an "Automation Error" aka Double Trap
  On Error GoTo 0
  'Raise the error to the caller program
  Err.Raise Number:=vbObjectError + 1, _
            Source:="Class: clsObjAdminPickListStandardTbl, Subroutine: Clear()", _
            Description:="Failed to Clear() class instance"
  Resume Exit_Clear

End Sub

'Lots of other methods in the class...

Public Function CommitToBE() As Boolean
On Error GoTo Err_CommitToBE

  Dim strSQL As String

  'Define a query to SELECT all of the records from the FE temp table in sorted order
  strSQL = "SELECT [pl].[authid],[pl].[authusername],[pl].[logtimestamp],[pl].[id],[pl].[sort],[pl].[active],[pl].[title]" & vbCrLf & _
           "FROM [" & Me.FETempTableName & "] AS [pl]" & vbCrLf & _
           "ORDER BY [pl].[sort],[pl].[title];"

  'Define attachment to database table specifics and execute commands via With block
  Set adoRStt = CreateObject("ADODB.Recordset")
  With adoRStt
    .ActiveConnection = CurrentProject.Connection
    .CursorType = adOpenDynamic
    .LockType = adLockOptimistic
    .Open strSQL

    'Was no record found?
    If .BOF Or .EOF Then
      CommitToBE = False
      GoTo Exit_CommitToBE
    Else
      'Try fetching this first record found
      If Me.Priv_CommitToBEFetch() Then
        CommitToBE = True
      Else
        'rrrrr??? Thought we had data...
        CommitToBE = False
        GoTo Exit_CommitToBE
      End If
    End If

    'Continue until .EOF
    While .EOF = False
      'Move onto the next record
      Call Me.CommitToBEFetchNext
    Wend
  End With

  'Close the database table
  adoRStt.Close

  'TRUNCATE the FE Temp Table
  Call Me.EmptyLocalTmpTbl

Exit_CommitToBE:
  'Clean up the connection to the database
  Set adoRStt = Nothing

  Exit Function

Err_CommitToBE:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardTbl, Function: CommitToBE()")
  CommitToBE = False
  Resume Exit_CommitToBE

End Function

'This API transfers the current record values from the adoRS object to this Class Object
'This should NEVER EVER EVER EVER EVER be directly called
'VBA does NOT support Private Functions in Classes, else I would have made this Private
Public Function Priv_CommitToBEFetch() As Boolean
On Error GoTo Err_Priv_CommitToBEFetch

  Dim thisOldRec As clsObjAdminPickListStandardItem
  Dim intFieldCounter As Integer
  Dim strThisField As String
  Dim UpdateFlg As Boolean

  UpdateFlg = False

  'Fetch the values found in the FE temp table
  'and send them directly to the real DB object for the BE table
  ObjBEDBTbl.authid = Nz(adoRStt!authid, 0)
  ObjBEDBTbl.logtimestamp = Nz(adoRStt!logtimestamp, vbNullString)
  ObjBEDBTbl.id = Nz(adoRStt!id, 0)
  ObjBEDBTbl.sort = Nz(adoRStt!sort, 0)
  ObjBEDBTbl.active = Nz(adoRStt!active, False)
  ObjBEDBTbl.title = Nz(adoRStt!title, vbNullString)

  'Detect INSERT / UPDATE based on the presence of a SQL Server ID value
  If ObjBEDBTbl.id = 0 Then
    'INSERT mode
    Call ObjBEDBTbl.Insert
  Else
    'UPDATE mode
    'Look up the object of the pre-edit state of this record by SQL Server ID
    Set thisOldRec = ObjAdminPickListStandardItems.Item(CStr(ObjBEDBTbl.id))

    'Test the sort values
    If ObjBEDBTbl.sort <> thisOldRec.sort Then
      UpdateFlg = True
      GoTo DoUpdate
    End If
    
    'Test the active values
    If ObjBEDBTbl.active <> thisOldRec.active Then
      UpdateFlg = True
      GoTo DoUpdate
    End If

    'Test the title values
    If ObjBEDBTbl.title <> thisOldRec.title Then
      UpdateFlg = True
      GoTo DoUpdate
    End If

DoUpdate:
    If UpdateFlg = True Then
      Call ObjBEDBTbl.Update
    End If
  End If

  'Set a good return code
  Priv_CommitToBEFetch = True

Exit_Priv_CommitToBEFetch:
  Exit Function

Err_Priv_CommitToBEFetch:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardTbl, Function: Priv_CommitToBEFetch(), Values: id=" & Nz(adoRStt!id, 0) & " title=" & Nz(adoRStt!title, vbNullString))
  Priv_CommitToBEFetch = False
  Resume Exit_Priv_CommitToBEFetch

End Function

'This API tries to move to the next record
Public Function CommitToBEFetchNext() As Boolean
On Error GoTo Err_CommitToBEFetchNext

  With adoRStt
    'Try moving to the next record
    .MoveNext
    If .EOF = True Then
      'End of result set reached
      CommitToBEFetchNext = False
    Else
      'Not at the end so try to read this record
      If Me.Priv_CommitToBEFetch = True Then
        CommitToBEFetchNext = True
      Else
        'Odd, thought we got to the next record...
        CommitToBEFetchNext = False
      End If
    End If
  End With

Exit_CommitToBEFetchNext:
  Exit Function

Err_CommitToBEFetchNext:
  Call errorhandler_MsgBox("Class: clsObjAdminPickListStandardTbl, Function: CommitToBEFetchNext()")
  CommitToBEFetchNext = False
  Resume Exit_CommitToBEFetchNext

End Function
Now I am using another class object (ObjBEDBTbl) to wrap calls to the BE DB, a SQL back end which has Stored Procedures for its interface. The ObjBEDBTbl is perfectly able to deal with Access tables. Just that the class this code is harvested from is encapsulating the FE temp table / cache of the real BE DB table. Records were previously downloaded to the temp table (this is for administration of a Pick List) and then when it comes time to Commit the changes back to the BE DB, these three methods scan the FE temp table looking for differences compared to the state the records were in when the class downloaded them from the BE DB, and notes differences by sending the data to the BE DB. It sounded to me like what you are talking about.

Update Note: I have updated this post to use Late-Binding syntax to create the ADO object(s). You will also need to use this post to obtain all of the constants ADO utilizes in order to have complete success with Late-Binding.

ADO Constants for use with Late Binding ActiveX Data Objects 2.8 Library
http://www.access-programmers.co.uk/forums/showthread.php?t=243088
 
Last edited:

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Hi Michael

Thank you so much for this solution. I will try this out at the weekend at home and see how it works.

Excuse my ignorance as I really am a novice in simpleton laymans terms what does this sentence mean. I'm not used to using proper lingo yet:

I do this sort of thing using an ADO.Recordset object defined at Class level so that the adoRS object survives as the class methods interact with each other.

Many thanks once again

Diane Downer
Novice
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
Excellent question! :D

Where you declare the objects has everything to do with the visibility scope of the object. (Same is true for simple variables.) Since I define the adoRStt object at the class level (that is, before the first class method, in the class header area) then that object is visible in ALL class methods. VBA keeps it alive and intact no matter which method of the class is executing. Since the CommitToBE involves three methods, this is IMPERATIVE that the adoRStt object be retained the entire time the Commit is executing.

If the adoRStt object was defined in a method, it would only last as long as that one method was executing ONE time.

If I defined it in a public module, it would exist globally to the entire application the entire time the application is running.

If I defined it at the top of a Form object, then it would exist in the context (scope) of that form for the entire time the Form remains open.

So, defining it at the top of the class means that it has visibility ONLY within the context of that class, and will exist as long as the class instance exists. These "DB objects" I define in a VBA Module so that they will exist the entire time the application is running.

Code:
Rem /************************************************************************************/
Rem /* FILENAME       :  modadminpicklists_bootstrap                                    */
Rem /* TYPE           :  VBA Module                                                     */
Rem /* DESCRIPTION    :  VBA code which creates objects needed for the picklist admin   */
Rem /*                   area of this application                                       */
Rem /*                                                                                  */
Rem /* AUTHOR         :  Michael D Lueck                                                */
Rem /*                   mlueck@lueckdatasystems.com                                    */
Rem /*                                                                                  */
Rem /* NEEDS          :                                                                 */
Rem /*                                                                                  */
Rem /* USEAGE         :                                                                 */
Rem /*                                                                                  */
Rem /* REVISION HISTORY                                                                 */
Rem /*                                                                                  */
Rem /* DATE       REVISED BY DESCRIPTION OF CHANGE                                      */
Rem /* ---------- ---------- -------------------------------------------------------    */
Rem /* 05/01/2012 MDL        Initial Creation                                           */
Rem /* 05/03/2012 MDL        Added creation of ObjUIValidationAdminPickListStandard obj */
Rem /* 05/22/2012 MDL        Added "NoSort" objects                                     */
Rem /* 05/23/2012 MDL        Added "AQE" objects                                        */
Rem /* 05/26/2012 MDL        Added "SykAssyFlg" objects                                 */
Rem /* 06/14/2012 MDL        Added "QualityContacts" objects                            */
Rem /* 06/15/2012 MDL        Added "PartsProdTeam" objects                              */
Rem /* 09/28/2012 MDL        Added "FARej" objects                                      */
Rem /* 10/02/2012 MDL        Added "BuyerCode" objects                                  */
Rem /************************************************************************************/

Option Compare Database
Option Explicit

Public ObjAdminPickListStandardTbl As New clsObjAdminPickListStandardTbl
That way all of the forms are able to interact with the DB objects as they have need to.
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Hi Michael

Thank you once again, I think I may need to read this over a bit but think I get what you are saying. Thank you for your time, I appreciate it very much indeed. I will let you know how I got on, I will be addressing this on Sunday so prob get feedback to you on Sunday Night or Monday. Have a fantastic weekend.

I truly hope one day I will reach even a quarter of your knowledge.

Kind Regards
Diane Downer
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
You are very welcome, Diane. Chat with you next week then.
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Hi Michael

I ran the code but it has stopped with an error:
compile error: ambiguous name detected against (Public logtimestamp As String)

Anyway I reread what I wrote and thought I may not have explained the situ as good as I could have. Here's another attempt, it may change things...

Our designer work with drawing numbers. However, they cannot always rely on themselves not to duplicate numbers so they want the (initial) drawing numbers created for them. I say initial this is not the case but an example of what I mean say you were designing a car - there would be one main drawing number, and this is the first number they are looking for, automated for them. To that effect I wrote the code against the main form:

Option Compare Database
Option Explicit
Private Sub Form_BeforeInsert(Cancel As Integer)
AssemblyID = Nz(DMax("AssemblyID", "tblAssembly")) + 1
End Sub

They enter very few details and it creates the autonumber, now they care their main drawing number. But if you think a car has many parts i.e a starter motor so they will create a drawing for that and another say for a gear box, each of these will have different numbers but created from the main number i.e car 1234 start 1234a gear box 1234ab1 but no further auto numbers are created for these via the database.

Having got their main number they work on their cad inventor or vault databases happily creating loads of drawings and then an excel sheet is produced with the main drawing number and all the various drawing numbers listed in the same column with the relevant details required for each drawing in the rows. However, I want the database to recognise the first drawing number and then upload all the details.

I created a code with uploads the excel sheet to become a temp table:
Option Compare Database
Option Explicit
Private Sub cmdOK_Click()
'-- Declare some useful variables
Dim StrFileName As String
Dim StrTableName As String
Dim StrSQL_rptImportAssembly As String
Dim StrSQL_rptBillofMaterials As String
Dim StrSQL_Append1 As String

'-- Read the file and user names entered by the user into the text boxes
StrFileName = Me.txtFileName
StrTableName = Me.txtUserName

'-- Link the spreadsheet to Access
DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel12Xml, Me.txtUserName, "C:\LinkExcel\" & Me.txtFileName, True
and that works fine too.

What I then needed then was to complete the rest of the code so the temporary table I created uploads itself to the database in the correct place: I created this code:

'-- Append some data
DoCmd.SetWarnings False
StrSQL_Append1 = "INSERT INTO tblAssemblyDetails (ItemNumber,Quantity,PartNumberId,Drawing,PartNumberDescription,Material,Supplier,Length,WidthOD,ThickID,Finish)SELECT Item,Qty,PartNumber,Drawing,Description,Material,Supplier,Length,Width_OD,Thickness_ID,Finish FROM " & StrTableName
DoCmd.RunSQL StrSQL_Append1

'-- Finally, remove the linked table (note that this just deletes the link, the spreadsheet file is not actually deleted)
DoCmd.DeleteObject acTable, StrTableName
'-- Give feedback to the user
MsgBox "Operation completed"
End Sub

Which does not have the desired result.

I have main assembly table for the main form and this is where the autonumber is created.

I have a assembly details table for the sub form and this is where I would like the the temporary table to load to but in the correct place. At the minutes it adds itself but not in the correct place. So when I open the form there are no details on the sub form.

I have main form this is where the main order number is generated and a sub form where all the details should be held and in the left hand column obviously the autonumber is linked to the sub form so I have:

Main Form
autonumber 1234 drawing name etc etc

Sub Form

1234 1234 car
1234 1234a starter motor
1234 1234ab1 gearbox

So I would like the final code when loading the temp table to Assembly Details to recognise the autonumber put upload to correct position 1234 against 1234 and then all the rest of the temp table to list underneath as it is.

This way when I open main form 1234 and click on sub form all the details will be listed as it does on the excel spreadsheet. This way they can seatch 1234 and see all the details for it listed below.

I hope I have made that a little easier to understand. In my awkward none techical terms. I truly am a novice and for example all the code you have written terminology I have no idea what for example commitToBE etc means thats how novice I am.

Sorry to be a pain so very desperate at the moment it is the only part of the code that is holding me up from moving forward and I am truly stumped.

Many thanks for all the help you can offer.

Kind Regards
Diane
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
I ran the code but it has stopped with an error:
compile error: ambiguous name detected against (Public logtimestamp As String)

I will address this quick point, then continue reading your post.

logtimestamp is a column in the table AND a class atribute (as all table columns are). So per the example code, I was suggesting you to create class attributes for all of the columns in your table.

Now, I happen to use the value of that column to capture the current timestamp at the time the record is saved (INSERT / UPDATE). For UPDATE operations, I qualifty the WHERE clause of the UPDATE to include both the unique ID col(s) of the record AND the previous value of the logtimestamp col. Should that same record have been updated by someone else while the person had the record "in edit mode" in the Access client, then the logtimestamp will no longer match and the UPDATE would fail to update any record. In this case I display a custom error suggesting that "perhaps someone else edited the record. Rollback and bring the record into edit mode again." This totally avoids the complexities of setting/checking record locks yet maintains data integrity in a multi-user environment.

Sample of my UPDATE SQL:
Code:
UPDATE [dbo].[projects]
SET [authid] = @authid,
    [logtimestamp] = CURRENT_TIMESTAMP,
    [title] = @title,
    [budget] = @budget,
    [rptactiveflg] = @rptactiveflg,
    [rpttitle] = @rpttitle
WHERE [id] = @id
AND [logtimestamp] = @logtimestamp;
This is SQL Server specific SQL. I believe Access uses the Now() function in place of CURRENT_TIMESTAMP, and you must handle quoting appropriately to capture the output of the VBA function Now() into the SQL statement.

Immediate Window:
Code:
? Now()
12/10/2012 9:44:51 AM
Yes, appears so, just formatted slightly different than SQL Server.
 
Last edited:

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Ok thank you Michael, bear with me I've never done anything like this before deep end.
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
I have no idea what for example commitToBE etc means thats how novice I am.

That is merely my function name in the class. Operationally it is committing back to the back-end database any changes from the front end temp table. Thus I thought it a similar task to what you were describing. The three class functions work together to move through the FE temp table, and note differences by issuing INSERT / UPDATE operations to the back end database.

Using DMax to obtain an autonumber is a bit dangerous. If two computers were grabbing a number at the same time, it could result in a duplicate ID number situation.

When I have rolled my own autonumber logic, I have used a separate ID tracking table which has cols KeyName / ID, where KeyName is a string and ID is the Long ID number. I have done the same sort of UPDATE as I pasted above.. updating WHERE the KeyName / OldID are a perfect match. If the KeyName / OldID is not found, I loop to try to obtain an ID, perhaps up to five times, then abort out of trying to obtain a new Unique ID.
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
Clarification Note: My suggestion for rolling your own ID tracking table...

To obtain the "next ID for a certain KeyName"...

1) First you would need SELECT out the current ID for KeyName.
2) +1 the ID
3) Then try to UPDATE the table as I explained above.
If that should fail then bump a fail counter +1 and try again from 1)
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Thank you Michael for your help, all above is difficult for me to understand but I shall try and work through it to comprehend.

Many thanks for your time.

Kind Regards
Diane
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
I have an existing main order table with a connecting sub details table, would like to add further details to the sub details table from a different table to increase the size of the order how to please.
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
In your post above, and since you have been referring to an orders table... I would perceive the orders table to have the order number, and the details associated with it would be the items on each order, correct?

So this "other table" you wish to harvest records from, would that be the items table, which orders will be placed against?
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Yes Michael the Orders table has the order number, the sub table has the order details conected by the order number and the 3rd table has been imported and has further orders that need to be inserted however, only one of these columns/rows details match the order number but want all the table uploaded once it has found the corresponding order number. Incidently at present the tables are not split.
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
Could you try to explain the purpose of the third table again? I did not understand what you meant.
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Sorry Michael, basically the first 2 tables are like normal tbl main is order number and subtbl the items ordered. However, at times additional items are added to the order and they need to be inserted against the appropriate order number and again imported from a spreadsheet however only one of the items on the whole of the spreadsheet will show the original order number normally within the first row of the spreadsheet so could have one row of additional orders or ten rows or more of additional orders but only the first row in each spreadsheet will identify which order number the whole of the spreadsheet relates to and the whole of the tble created from the spreadsheet needs to be inserted or updated whichever is the best way forward.

Many thanks Michael
 

mdlueck

Sr. Application Developer
Local time
Today, 08:20
Joined
Jun 23, 2011
Messages
2,631
So this third table (coming from a spreadsheet), that already knows the correct order number... so perhaps a query that collects up items for the order needs to check the OrderItems table first, and then also search through this third table for possible items?

Or are you asking to import to the OrderItems table qualifying records from the third table as an Order is process... thus the third table would not need to be queried after the OrderItems from that table are pulled into the main OrderItems table?
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
I have already imported the spreadsheet with the additional orderitems on and this is the created 3rd temp table (once this table is uploaded the table will be deleted) and the process will be repeated over and over again for each time a spreadsheet is created. The difference with this spreadsheet is, is that whilst there are multiple order items on the spreadsheet, they all only relate to one order number. The problem is the order number is only mentioned once on the spreadsheet for example:

Main table Order Number
123456789
Subtable order items connected by the order number
123456789 585858 figs
123456789 586781 box of roses
123456789 567681 oranges

3rd temp table created from spreadsheet
123456789 flowers
567681 oranges
586781 box of roses

So the whole order items from the 3rd table is relevant but the order number is only listed once on the first line. All records on the spreadsheet are qualifying records and need to be uploaded on the 2nd table the subtable like this

123456789 123456789 flowers
123456789 567681 oranges
123456789 586781 box of roses
so the left hand column will be created automatically as each row of order is pulled to add to the subtable and columns 2 and 3 are what is added as long as the code is such that it recognises and matches the first row order number it uploads the whole table.

Sorry Michael not really explaining this too well.

Regards
Diane
 

Ridgeway

Registered User.
Local time
Today, 05:20
Joined
Dec 7, 2012
Messages
16
Unless it is all possible for it the search the forms i.e I have the main form orders and sub form order details but it would need to find on the either the main form or the subform the order number i.e. 123456789 and on doing so complete insert details onto the subform as this would fill the tables, as if we were physically entering the details onto the form. I am not sure if this is possible at all or any easier.

Many thanks
Diane
 

Users who are viewing this thread

Top Bottom