2016-06-24 2 views
0

Access 2007内で作業する。データベースに苦労して、出荷/受領に基づいてリアルタイムで更新された在庫量がリアルタイムに表示されます。私は次のコードをお勧めしましたが、コンパイルエラーが発生しています。Access 2007、VBA:コンパイルエラー:予期した文末の末尾

Private Sub Command62_Click() 
'Arguments: ContID = Container to be reported on 
' AsOfDate = the date at which quantity is to be calculated 
'If missing, all transactions are included 
' Return: Quantity on hand. Zero on error. 

Dim db As DAO.Database 'current database 
Dim rs As DAO.Recordset ' various recordsets 

Dim lngContID As Long  ' ContID as long 
Dim strAsOf As String  ' AsOfDate as string 
Dim strLasShipRec As String ' Last ship date as string 
Dim strDateClause As String 'Date clause to be used in SQL statement 
Dim strSQL As String   ' SQL statement 
Dim lngOnHand As Long  'IOnHand inventory 

If Not IsNull(CONTID) Then 
'Initialize: Validate and Convert parameters 

Set db = CurrentDb() 
lngContID = CONTID 
If IsDate(AsOfDate) Then 
strAsOf = "#" & Format$(AsOfDate, "mm\/dd\/yyyy") & "#" 

'Get the LastShipRec date and quantity fo this container 

If Len(strAsOf) > 0 Then 
strDateClause = "AND (LastShipRec<="&strAsOf&")" 
End If 

strSQL = "Select Top 1 LastShipRec, Quantity FROM tblContInventory"& "WHERE ((ContID = "&lngContID&")"&strDateClause)&";ORDER BY LastShipRec DESC;" 

それでコンパイル '予想文の終わり' を与えている:誰かが正しい方向に私を指すことができるだろう

strSQL = "Select Top 1 LastShipRec, Quantity FROM tblContInventory"& "WHERE ((ContID = "&lngContID&")"&strDateClause)&";ORDER BY `enter`LastShipRec DESC;" 

If Len(strAsOf) > 0 Then 

strDateClause = "AND (LastShipRec<="&strAsOf&")" 
End If 

?このエラーを修正するにはどうすればよいですか?

答えて

0

strDateClauseの後ろからブラケットを取り除くと、SQLにも ""が入る必要があります。最後の前に。それを見ると、strDateClauseは使用しません。

1

strSQL = ...の行が長い文字列を作成しようとしています。この長い記述を見てみると、かっこが間違っていて、最初の行に余分なセミコロンがあるように見えます。 SQL文字列を構築する場合

strSQL = "Select Top 1 LastShipRec, Quantity FROM tblContInventory"& "WHERE ((ContID = "&lngContID&")" & strDateClause & ") ORDER BY LastShipRec DESC;" 

を試してみて、私は文字列を作成し、作成した文字列が有効なSQLステートメントであるかどうかを確認するために、デバッグのためのDebug.Printを行うことをお勧めします。

+0

このSQL文では、tblContInventoryとWHEREの間にもスペースが必要です。 '... tblContInventory"& "WHERE ..."を 'tblContInventory WHERE ... 'に置き換えてみてください。 –

関連する問題