0

here's my problem. I have 2 tables tvehicle and tPMCL the tVehicle table has a list of our vehicles, and the tPMCL holds when preventitive maint. is done.

tvhhicle.VehicleTagnumber holds the actual plate number, and tPMCL.Tag holds only a Index of a look up of that number from when it was entered, I wish it had the tag number so when i do loops through my data comparing it would be able to match up, as it is:

it's comparing something along the lines of "XPE 269" to 1 and that's not working so well.

Any ideas? the answer may not be a VBA answer it may be a diferent way to do the lookup in the first place. But I just can't find another way to do the lookup and actually store the plate number and not an index of it.

4

1 回答 1

1

看来您认为的索引实际上是外键。这是一件好事。这意味着如果 VehicalTagNumber 在哪里更改(例如错误的输入),则不需要更新引用表。

如果您需要遍历 tPMCL 并且需要相应的标签号,您可以执行以下两项操作之一。

您可以使用 Dlookup 在每个循环中获取它。例如

Dim strTag As String
strTag = DLookup("[VehicleTagnumber]", "tvhhicle","[Id] = 1")

但是,对于大量记录,这将很慢。

相反,只需将您的记录集基于连接两个表的 SQL 语句,而不是直接打开一个表。

Dim dbVehicle As Object 
Dim rstVehicle As Object 
Dim fldEnumerator As Object 
Dim fldColumns As Object 
Dim strSQL as String

Set dbVehicle = CurrentDb 
Set rstVehicle = dbVehicle.OpenRecordset("tVehicle") 
Set fldColumns = rstVehicle.Fields 

strSQL = "SELECT * FROM tMPCL m INNER JOIN tVehicle v ON m.Tag = v.ID" 

Set rsttPMCL = dbVehicle.OpenRecordset(strSQL)
于 2012-06-05T16:39:58.773 回答