我有一個Access應用程序爲每個記錄使用一個UID,但它不匹配到SQL中的記錄順序。 (即我的12845的UID對應於Access中的記錄號碼12834)訪問 - 在記錄中查找字符串,然後轉到該記錄
我有一個搜索框,我已經創建了應該搜索Access DB並拉起記錄,找到匹配的UID,但是,我編寫代碼的方式是它將記錄與UID匹配的記錄編號(因此它將使用UID 12845獲得記錄號12845而不是記錄12834)。
我一直坐在這上幾天,我找不到解決辦法。搜索互聯網並沒有什麼幫助。如果任何人有一個想法,如何可以匹配一個字符串,並轉到記錄與試圖解析自己的記錄信息,那就太好了。
以下是我使用的代碼示例。它需要一個日期字符串,並在記錄查找字符串,獲取UID,然後嘗試轉到相應的記錄:
Private Sub FindBarCodeDate_Click()
Dim Barcode As String
Dim EndDate As String
If IsNull(BarcodeSearch.Value) Then
If IsNull(DateSearch.Value) Then
GoTo Done
Else
EndDate = DateSearch.Value
End If
Else
If IsNull(DateSearch.Value) Then
Barcode = BarcodeSearch.Value
Else
Barcode = BarcodeSearch.Value
EndDate = DateSearch.Value
End If
End If
Dim rs As New ADODB.Recordset
Dim strSql As String
Dim TSD As String
If Barcode <> "" Then
If EndDate <> "" Then
strSql = "SELECT [TSD ID] FROM dbo_barAdultCollectionData WHERE Barcode = '" & Barcode & "' AND [End Date] = '" & EndDate & "'"
On Error GoTo Done
rs.Open strSql, CurrentProject.Connection
TSD = rs.Fields.Item(0)
rs.Close
DoCmd.FindRecord TSD, acEntire, False, acSearchAll, False, acAll, True
Set rs = Nothing
Else
strSql = "SELECT [TSD ID] FROM dbo_barAdultCollectionData WHERE Barcode = '" & Barcode & "'"
On Error GoTo Done
rs.Open strSql, CurrentProject.Connection
TSD = rs.Fields.Item(0)
rs.Close
DoCmd.FindRecord FindWhat:=TSD, Match:=acEntire, MatchCase:=False, Search:=acSearchAll, SearchAsFormatted:=False, OnlyCurrentField:=acAll, FindFirst:=True
Set rs = Nothing
End If
ElseIf Barcode = "" Then
If EndDate <> "" Then
strSql = "SELECT [TSD ID] FROM dbo_barAdultCollectionData WHERE [End Date] = '" & EndDate & "'"
On Error GoTo Done
rs.Open strSql, CurrentProject.Connection
TSD = rs.Fields.Item(0)
rs.Close
DoCmd.FindRecord FindWhat:=TSD, Match:=acEntire, MatchCase:=False, Search:=acSearchAll, SearchAsFormatted:=False, OnlyCurrentField:=acAll, FindFirst:=True
Set rs = Nothing
End If
Else
Done:
SearchError.Caption = "Invalid Search Term!"
End If
End Sub
謝謝!
Wow其他塊只能通過跳轉到標籤才能到達。我不知道以前我見過這個。無法想象它永遠是可取的。 –
因此,您在ID表中查找ID並在ID表中搜索該ID時,ID實際上並不相同。我很困惑你如何期望它從SQL ID轉換到Access ID。讓我們回去吧。在英文中,如果我們手動查看打印的表格,我們將如何知道哪個Access記錄與給定的SQL記錄一起使用? –