ECEstudent
Registered User.
- Local time
- Today, 13:35
- Joined
- Jun 12, 2013
- Messages
- 153
Hi,
I have 2 tables and 1 query. Table dbo_RepOrderItem includes columns:
RepId
OrderNumber
Item
ShipDate
SerialCardID
Table tbl_LBP Sales Location Num includes columns:
Location ID
Rep Region Code
What I've been doing so far through my code is working through a query 'CalculateTotal' which looks up a structure number (Which I enter through an InputBox) from table dbo_RoicStructure, gets the SerialCardID from the same table and collects the associated RepId,OrderNumber,ShipDate from table dbo_RepOrderItem and checks that the OrderNumber(s) returned exist in column Location ID in table tbl_LBP Sales Location Num. It also checks that Rep Region Code is not equal to 'INT' nor 'inte'.
My code for all of this works just fine. What I am trying to do now is simplify my results. I want to only return rows that do not have the same Item, OrderNumber, and RepID.
Fore example:
OrderNumber: Item: RepID:
11 3 1
12 3 1
11 4 1
11 3 1
14 7 4
16 8 8
It would now count 5 existing RepID(s) rather than 6 because it would have deleted the duplicated row. This should only be deleted in the user's table not the actual table.
And speaking of the user's table. What I have been doing so far is only returning the results (right now it returns 6, which as I explained above is incorrect) but I also want to return a table or query that would should the user the work behind the returned number.
This is my code:
Thank you in advance
I have 2 tables and 1 query. Table dbo_RepOrderItem includes columns:
RepId
OrderNumber
Item
ShipDate
SerialCardID
Table tbl_LBP Sales Location Num includes columns:
Location ID
Rep Region Code
What I've been doing so far through my code is working through a query 'CalculateTotal' which looks up a structure number (Which I enter through an InputBox) from table dbo_RoicStructure, gets the SerialCardID from the same table and collects the associated RepId,OrderNumber,ShipDate from table dbo_RepOrderItem and checks that the OrderNumber(s) returned exist in column Location ID in table tbl_LBP Sales Location Num. It also checks that Rep Region Code is not equal to 'INT' nor 'inte'.
My code for all of this works just fine. What I am trying to do now is simplify my results. I want to only return rows that do not have the same Item, OrderNumber, and RepID.
Fore example:
OrderNumber: Item: RepID:
11 3 1
12 3 1
11 4 1
11 3 1
14 7 4
16 8 8
It would now count 5 existing RepID(s) rather than 6 because it would have deleted the duplicated row. This should only be deleted in the user's table not the actual table.
And speaking of the user's table. What I have been doing so far is only returning the results (right now it returns 6, which as I explained above is incorrect) but I also want to return a table or query that would should the user the work behind the returned number.
This is my code:
Code:
Option Compare Database
Option Explicit
Sub SearchPartNumber_Entered()
Dim txtPartNumber As Variant
Dim rst As Recordset
Dim rstt As Recordset
Dim u As Variant
Dim i As Integer
Dim n As Integer
Dim Arr() As String
Dim Arry() As String
Dim x As Variant
Dim y As Variant
Dim varCode As Variant
Dim varCod As Variant
Dim Count As Integer
Dim Count2 As Integer
Dim VldOrdrNbrDestination As Integer
txtPartNumber = InputBox("Enter Part Number:")
If Not txtPartNumber = "" Then
VldOrdrNbrDestination = 0
If DCount("ChildProductNbr", "dbo_ProductStructure", "[ChildProductNbr] = '" & txtPartNumber & "'") > 0 Then
MsgBox "Part Number Found!"
Count = DCount("ChildProductNbr", "dbo_ProductStructure", "[ChildProductNbr] = '" & txtPartNumber & "'")
MsgBox Count
Set rst = CurrentDb.OpenRecordset( _
"Select * from dbo_ProductStructure where ChildProductNbr= '" & txtPartNumber & "'")
While rst.EOF = False
ReDim Preserve Arr(i)
Arr(i) = rst.Fields("ParentProductNbr")
i = i + 1
rst.MoveNext
Wend
x = Arr
For Each varCode In x
varCode = Replace(varCode, "-", "*")
varCode = Trim(varCode) 'trim extra spaces from varCode
MsgBox "'*" & varCode & "*'"
u = varCode
MsgBox "Look for structure"
If DCount("Structure", "CalculateTotal", "[Structure] like '*" & u & "*'") > 0 Then 'If what the user inputs exists in database, enter if statement
Count2 = DCount("Structure", "CalculateTotal", "[Structure] like '*" & u & "*'")
MsgBox "Number of Structures Found = " & Count2 & ""
Set rstt = CurrentDb.OpenRecordset( _
"Select * from CalculateTotal where ([Structure] like '*" & u & "*')", dbOpenDynaset, dbSeeChanges)
While rstt.EOF = False
ReDim Preserve Arry(n)
Arry(n) = rstt.Fields("RepId")
n = n + 1
rstt.MoveNext
Wend
y = Arry
For Each varCod In y
If DCount("[Location ID]", "[tbl_LBP_Sales Location Num]", "[Location ID] = '" & varCod & "'") > 0 Then
If Not "[Rep Region Code]" = "INT" And Not "[Rep Region Code]" = "inte" Then
VldOrdrNbrDestination = VldOrdrNbrDestination + 1
End If
End If
Next varCod
MsgBox "Number of orders: '" & VldOrdrNbrDestination & "'"
Else
MsgBox "Structure Not Found"
End If
Next varCode
Else
MsgBox "Part Number Not Found"
End If
Else
MsgBox "Enter Part Number"
End If
End Sub
Thank you in advance
