我有一个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记录一起使用? –