2016-06-24 3 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 문자열을 구축 한 후 생성 된 문자열이 유효한 SQL 문이 있는지 확인하기 위해 디버깅을 Debug.Print를 수행 할 때

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

보십시오.

+0

이 SQL 문은 tblContInventory와 WHERE 사이에도 공백이 필요합니다. '... tblContInventory "&"WHERE ... "를'tblContInventory WHERE ... '로 바꾸십시오. –