2009-06-18 153 views
0

我正試圖根據分配給他們的採購訂單來計算髮送給供應商的所有物料。但我似乎無法控制顯示基於採購訂單實例的多個項目 - 它會一直拋出一個#name?或#error!當表單被激活時,文本框中的消息。DCount與SQL SELECT COUNT(*)?

爲tblPODetail

CREATE語句
USE [instkeeper_test] 
GO 


SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 

CREATE TABLE [dbo].[tblPODetail](
    [intPurchaseOrderInstance] [int] IDENTITY(1,1) NOT NULL, 
    [intPONumber] [int] NOT NULL, 
    [datDateEntered] [datetime] NOT NULL, 
    [bolPOOpen] [bit] NOT NULL, 
    [intRMANumber] [nvarchar](255) NULL, 
    [strSupplierCode] [nvarchar](50) NOT NULL, 
    [strSupplierLastAddress] [nvarchar](50) NULL, 
    [strSupplierLastCity] [nvarchar](50) NULL, 
    [strSupplierLastState] [nvarchar](50) NULL, 
    [strSupplierLastPostalCode] [nvarchar](50) NULL, 
    [strSupplierLastCountry] [nvarchar](50) NULL, 
    [strSupplierLastPhone] [nvarchar](50) NULL, 
    [strSupplierLastFax] [nvarchar](50) NULL, 
    [datDateSent] [datetime] NULL, 
    [datDateReceived] [datetime] NULL, 
    [bolAdvGageTrakNoTouch] [bit] NOT NULL, 
    [bolAdvHardCopies] [bit] NOT NULL, 
    [bolFreightShip] [bit] NOT NULL, 
    [bolReturnableUsed] [bit] NOT NULL, 
    [bolInHouse] [bit] NOT NULL, 
    [strUPSTrackNumOut] [nvarchar](255) NULL, 
    [strFedExTrackNumOut] [nvarchar](255) NULL, 
    [strFreightTrackNumOut] [nvarchar](255) NULL, 
    [strUPSTrackNumIn] [nvarchar](255) NULL, 
    [strFedExTrackNumIn] [nvarchar](255) NULL, 
    [strFreightTrackNumIn] [nvarchar](255) NULL, 
    [SSMA_TimeStamp] [timestamp] NOT NULL 
) ON [PRIMARY] 

GO 

ALTER TABLE [dbo].[tblPODetail] WITH CHECK ADD CONSTRAINT [SSMA_CC$tblPODetail$strSupplierCode$disallow_zero_length] CHECK ((len([strSupplierCode])>(0))) 
GO 

ALTER TABLE [dbo].[tblPODetail] CHECK CONSTRAINT [SSMA_CC$tblPODetail$strSupplierCode$disallow_zero_length] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__intPO__6C190EBB] DEFAULT ((0)) FOR [intPONumber] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__datDa__6D0D32F4] DEFAULT (getdate()) FOR [datDateEntered] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__bolPO__6E01572D] DEFAULT ((1)) FOR [bolPOOpen] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__bolAd__6EF57B66] DEFAULT ((1)) FOR [bolAdvGageTrakNoTouch] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__bolAd__6FE99F9F] DEFAULT ((1)) FOR [bolAdvHardCopies] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__bolFr__70DDC3D8] DEFAULT ((0)) FOR [bolFreightShip] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__bolRe__71D1E811] DEFAULT ((0)) FOR [bolReturnableUsed] 
GO 

ALTER TABLE [dbo].[tblPODetail] ADD CONSTRAINT [DF__tblPODeta__bolIn__72C60C4A] DEFAULT ((0)) FOR [bolInHouse] 
GO 

爲tblPOGaugeDetail

的,我想計數出現在

SELECT dbo_tblPODetail.intPurchaseOrderInstance, dbo_tblPODetail.strSupplierCode, dbo_tblPODetail.bolPOOpen, dbo_tblPODetail.intPONumber, dbo_tblPODetail.datDateSent 
FROM dbo_tblPODetail 
WHERE (((dbo_tblPODetail.bolPOOpen)=True)) 
ORDER BY dbo_tblPODetail.datDateSent; 

我有采購訂單的詳細信息CREATE語句

USE [instkeeper_test] 
GO 


SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 

CREATE TABLE [dbo].[tblPOGaugeDetail](
    [intItemPOID] [int] IDENTITY(1,1) NOT NULL, 
    [intGagePOID] [int] NOT NULL, 
    [strGageDetailID] [nvarchar](50) NULL, 
    [datGageSent] [datetime] NULL, 
    [datGageReceived] [datetime] NULL, 
    [bolGageCalibrate] [bit] NOT NULL, 
    [bolGageRepair] [bit] NOT NULL, 
    [bolGageEvaluate] [bit] NOT NULL, 
    [bolGageAccredited] [bit] NOT NULL, 
    [bolGageReturned] [bit] NOT NULL, 
    [bolGageException] [bit] NOT NULL, 
    [bolGageExceptResolved] [bit] NOT NULL, 
    [bolGageLeavePriceBlank] [bit] NOT NULL, 
    [intGageCost] [real] NULL, 
    [intTurnaroundDaysOut] [int] NULL, 
    [SSMA_TimeStamp] [timestamp] NOT NULL, 
CONSTRAINT [tblPOGaugeDetail$PrimaryKey] PRIMARY KEY CLUSTERED 
(
    [intItemPOID] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] WITH CHECK ADD CONSTRAINT [tblPOGaugeDetail$tblPODetailtblPOGaugeDetail] FOREIGN KEY([intGagePOID]) 
REFERENCES [dbo].[tblPODetail] ([intPurchaseOrderInstance]) 
ON UPDATE CASCADE 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] CHECK CONSTRAINT [tblPOGaugeDetail$tblPODetailtblPOGaugeDetail] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [intGagePOID] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((1)) FOR [bolGageCalibrate] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [bolGageRepair] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [bolGageEvaluate] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [bolGageAccredited] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [bolGageReturned] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [bolGageException] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [bolGageExceptResolved] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [bolGageLeavePriceBlank] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [intGageCost] 
GO 

ALTER TABLE [dbo].[tblPOGaugeDetail] ADD DEFAULT ((0)) FOR [intTurnaroundDaysOut] 
GO 

查詢語句有點沮喪,因爲我已經讀了一些DCount()和SELECT COUNT(*),但是似乎無法讓他們工作。任何幫助將不勝感激!提前致謝!

- 編輯2008.02.04 @1542小時 -

這是SELECT COUNT我試圖在代碼中使用時,子窗體的對當前事件觸發的例子:

SELECT COUNT(*) AS ItemsSent 
FROM [dbo_tblPOGaugeDetail] 
WHERE [dbo_tblPOGageDetail]![intGagePOID] = [dbo_tblPODetail]![intPurchaseOrderInstance] 

這是連接到子窗體中控件的= DCOUNT語句的示例。

=DCOUNT("*", "[dbo_tblPOGaugeDetail]", "[intGagePOID] = [Forms]![frmSupplierInfoMain]![subfrmOpenPOBySupplierID]![intPurchaseOrderInstance]") 

這些都沒有工作 - 可悲的是。

+0

您能向我們展示您嘗試執行的選擇計數嗎? – BIBD 2009-06-18 20:15:36

+0

我假設當您手動運行該選擇查詢,它的工作。你如何得到TextBox的結果? – BIBD 2009-06-18 21:26:11

回答

1

您的查詢沒有計數(*)嗎?

使用DCount的第一個參數的實際字段名稱 從where字符串中獲取控件名稱。

For DCOUNT("[intItemPOID],"[dbo_tblPOGaugeDetail]","[intGagePOID]=" & Forms]![frmSupplierInfoMain]![subfrmOpenPOBySupplierID]![intPurchaseOrderInstance])