"No New Data Added" on form (1 Viewer)

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
Hi guys, I have an issue whereby my code does not detect new data when i import the excel file to access. I have posted this question in another forum, unfortunately i cannot get much help from there. I hope i will be able to get helps and solve this issue here! Any help offers is appreciated! Thank you!
LINK: http://www.accessforums.net/showthread.php?t=68899

I use date for my dlookup because the data will be updated every night thus, i use date to indicate new data.

My code for the import button on my form:
Private Sub cmdImport_Click()
Dim filepath As String
filepath = "C:\Users\User\Desktop\FabricPO.xlsx"
If FileExist(filepath) Then
DoCmd.TransferSpreadsheet acImport, , "TempFromExcel", filepath, True
If IsNull(DLookup("[Date]", "NewFabricPO")) Then
MsgBox "No new data to add"
Else
DoCmd.OpenQuery "qryappend", acViewNormal
End If
Else
MsgBox "File not found. Please check filename or file location."
End If
Dim SQLDelete As String
SQLDelete = "delete * from TempFromExcel"
DoCmd.RunSQL SQLDelete
End Sub

Function FileExist(sTestFile As String) As Boolean

'this function does not use DIR since it is possible that uou might have
'been in the middle of running DIR against another directory in
'an attempt to match one directory against another
'it does not handle wildcard characters

Dim lSize As Long
On Error Resume Next
'Preset length to -1 because files can be zero bytes in length
lSize = -1
'get the length of the file
lSize = FileLen(sTestFile)
If lSize > -1 Then
FileExist = True
Else
FileExist = False
End If

End Function

I use table "TempFromExcel to store duplicate data.
NewFabricPO is actually a unmatched query, and based on this table i would be able to add data that are not found in NewFabricPO table.
What is the SQL of the query "qryappend"? - this is to append all my data from NewFabricPO to my main table.


SQL for query "NewFabricPO"
SELECT TempFromExcel.[PO Type], TempFromExcel.Season, TempFromExcel.[Style NO], TempFromExcel.[GL Lot], TempFromExcel.Name, TempFromExcel.[Supplier ID], TempFromExcel.PO, TempFromExcel.[User ID], TempFromExcel.Name1, TempFromExcel.Line, TempFromExcel.Release, TempFromExcel.Date, TempFromExcel.Classification, TempFromExcel.Content, TempFromExcel.[Material Name], TempFromExcel.[Yarn Size and Type], TempFromExcel.[Fabric Weight], TempFromExcel.[Fabric Cuttable Width], TempFromExcel.Reference, TempFromExcel.Fabrication, TempFromExcel.Color, TempFromExcel.[Our Qty], TempFromExcel.UOM, TempFromExcel.[Supplier Qty], TempFromExcel.UOM1, TempFromExcel.[Unit Price], TempFromExcel.[Currency Code], TempFromExcel.Company, TempFromExcel.Approve, TempFromExcel.Canceled, TempFromExcel.[PO Date], TempFromExcel.[Garment Del Date], TempFromExcel.FOB
FROM TempFromExcel LEFT JOIN FabricPO ON TempFromExcel.[Date] = FabricPO.[Date]
WHERE (((FabricPO.Date) Is Null));

SQL for query "qryappend"
INSERT INTO FabricPO ( ID, [Date], PO, [Style NO], [GL Lot], Fabrication, [Fabric Cuttable Width], Color, [Our Qty], [Supplier Qty], Approve )
SELECT FabricPOQuery.ID, FabricPOQuery.Date, FabricPOQuery.PO, FabricPOQuery.[Style NO], FabricPOQuery.[GL Lot], FabricPOQuery.Fabrication, FabricPOQuery.[Fabric Cuttable Width], FabricPOQuery.Color, FabricPOQuery.[Our Qty], FabricPOQuery.[Supplier Qty], FabricPOQuery.Approve
FROM FabricPOQuery INNER JOIN FabricPO ON FabricPOQuery.ID = FabricPO.ID;
 

bob fitz

AWF VIP
Local time
Today, 12:45
Joined
May 23, 2011
Messages
4,726
I think it would be prudent to advise members of the other forum that you have also posted the question here, particularly as ssanfu has made several posts in an attempt to help.
 
Last edited:

JHB

Have been here a while
Local time
Today, 13:45
Joined
Jun 17, 2012
Messages
7,732
Is the query "NewFabricPO" returning records?
 

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
I think it would be prudent to advise members of the other forum that you have also posted the question here, particularly as ssanfu has made several posts in an attempt to help.

Alright thank you!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:45
Joined
May 7, 2009
Messages
19,246
use NewFabricPO query in your qryAppend.

you don't need to use Join on your "qryappend" since already it was linked and filtered on your NewFabricPO.
 

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
use NewFabricPO query in your qryAppend.

you don't need to use Join on your "qryappend" since already it was linked and filtered on your NewFabricPO.

Private Sub cmdImport_Click()
Dim filepath As String
filepath = "C:\Users\User\Desktop\FabricPO.xlsx"
If FileExist(filepath) Then
DoCmd.TransferSpreadsheet acImport, , "TempFromExcel", filepath, True
If IsNull(DLookup("[Date]", "NewFabricPO")) Then
MsgBox "No new data to add"
Else
DoCmd.OpenQuery "NewFabricPO", acViewNormal
End If

I have change, but it still wont work
 

JHB

Have been here a while
Local time
Today, 13:45
Joined
Jun 17, 2012
Messages
7,732
Post your database with some sample data.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:45
Joined
May 7, 2009
Messages
19,246
you said that it is returning the records from NewFabricPO query?
i think you need to dump the returned records to Temporary Table and

Append from this Temporary Table:


On Error Resume Next

Docmd.RunSQL "Drop Table "zzNewFabricPO;"
DoCmd.RunSQL "SELECT * Into zzNewFabricPO FROM NewFabricPO;"


change "qryappend" to append from zzNewFabricPO".


but, wait, since, zzNewFabricPO does not exists yet, you might try to create it first
by copying/paste the structure Only of the original FabricPO.
 

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
you said that it is returning the records from NewFabricPO query?
i think you need to dump the returned records to Temporary Table and

Append from this Temporary Table:


On Error Resume Next

Docmd.RunSQL "Drop Table "zzNewFabricPO;"
DoCmd.RunSQL "SELECT * Into zzNewFabricPO FROM NewFabricPO;"


change "qryappend" to append from zzNewFabricPO".


but, wait, since, zzNewFabricPO does not exists yet, you might try to create it first
by copying/paste the structure Only of the original FabricPO.

I do have a temp table
 

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346

Attachments

  • Sampledata.xlsx
    9.8 KB · Views: 131
  • Sample.accdb
    456 KB · Views: 152

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
you said that it is returning the records from NewFabricPO query?
i think you need to dump the returned records to Temporary Table and

Append from this Temporary Table:


On Error Resume Next

Docmd.RunSQL "Drop Table "zzNewFabricPO;"
DoCmd.RunSQL "SELECT * Into zzNewFabricPO FROM NewFabricPO;"


change "qryappend" to append from zzNewFabricPO".


but, wait, since, zzNewFabricPO does not exists yet, you might try to create it first
by copying/paste the structure Only of the original FabricPO.

Where should i add this code?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:45
Joined
May 7, 2009
Messages
19,246
on your sample database, there is nothing to add, since the records in TempSampleDataFromExcel is merely duplication of first 25 records of MainSampleData
 

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
Your query is quiet different from what you show in your post, which one is correct?
This one -

Or this one?

The first one is based on the sample database, as my data contain sensitive information hence i am unable to attached my actual database here.
 

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
on your sample database, there is nothing to add, since the records in TempSampleDataFromExcel is merely duplication of first 25 records of MainSampleData

If i delete some data from the Mainsampledata table, it will still still show no new data added
 

JHB

Have been here a while
Local time
Today, 13:45
Joined
Jun 17, 2012
Messages
7,732
Your show some SQL-string for a query in your post, but in your database it is quiet different, and then you complain over you don't get much help! :mad:
 

luzz

Registered User.
Local time
Today, 04:45
Joined
Aug 23, 2017
Messages
346
Your show some SQL-string for a query in your post, but in your database it is quiet different. :mad:

Yeah, I know. As the data from my actual database is confidential. Therefore, i came up with this sample database with the exact same code and query.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:45
Joined
May 7, 2009
Messages
19,246
here try this, delete first all records from MainSampleData before running the FORM.

check and view NewSampleData query.
 

Attachments

  • Sample.zip
    31.9 KB · Views: 131

Users who are viewing this thread

Top Bottom