topdesk123
Registered User.
- Local time
- Yesterday, 23:44
- Joined
- Mar 28, 2013
- Messages
- 53
Hello all!
I have read too many threads I think and am now totally confused. I have an inventory table - linked to an inventorylocation table. By inventoryID. When it comes time to count, I want users to be able to choose multiple count locations. Which I use a list box filled with locations (text field). Once the locations are chosen there's a button with this code (which I found on one of the forumns, behind it
I have read too many threads I think and am now totally confused. I have an inventory table - linked to an inventorylocation table. By inventoryID. When it comes time to count, I want users to be able to choose multiple count locations. Which I use a list box filled with locations (text field). Once the locations are chosen there's a button with this code (which I found on one of the forumns, behind it
Code:
=
varItem
Dim db As DAO.Database
Dim strNewQueryName As String
Dim oQuery As New QueryDef
Set db = CurrentDb
Dim strSql As String
Dim varItem As String
Dim txtsql As String
Dim i As Variant
varItem = ""
For Each i In Me!
[List].ItemsSelected
If varItem <> "" Then
varItem = varItem & " , "
End If
varItem = varItem & Me!
[List].ItemData(i)
Next i
strSql = "SELECT *, Inventory.InventoryID, Inventory.ItemDescription, Inventory.[Reorder Level], Inventory.Units, Inventory.TargetStockUnit, InventoryLocation.Location, Locations.LocationID " & vbCrLf & _
"FROM Inventory INNER JOIN (Locations INNER JOIN InventoryLocation ON Locations.Location = InventoryLocation.Location) ON Inventory.InventoryID = InventoryLocation.InventoryID;" 'Debug.Print txtSQL
strNewQueryName = "qryIDs"
Set oQuery = db.QueryDefs(strNewQueryName)
If oQuery.Name = "" Then
' query doesn't exist
db.CreateQueryDef strNewQueryName, txtsql
Else
' query exists; replace existing SQL
oQuery.SQL = txtsql
End If
oQuery.Close
DoCmd.OpenQuery strNewQueryName
Cleanup:
Set oQuery = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
If Err.Number = 3265 Then
' Item not found in this collection.
' query does not exist
Debug.Print "Caught " & Err.Number & ": " & Err.Description
Resume Next
Else
Debug.Print Err.Number & ": " & Err.Description
Resume Cleanup
End If[CODE]
I would like it to produce the SQL string behind the report "Count Inventory". I have tried this 1000 different ways and just don't get it. I thank you in advance for any help you can give me.