Question : Using DoCMD.FindRecord getting runtime error 2162

I have a form on which there is a combo box, which gets its data from a number field in a table, which has been sorted distinctly into descending order. What I want to be able to do is if the user changes the combo box number to something else then it moves to that record.

The code I wrote looks like this:

Private Sub Shipment_Number_Change()
  Dim ShipmentNumber As Integer
    [Shipment Number].SetFocus
    ShipmentNumber = [Shipment Number].Value
    Debug.Print ShipmentNumber
    DoCmd.FindRecord ([ShipmentNumber])
End Sub

I put the debug.print in there so I could check that the code correctly gets the right number (which it does), but because the control is not bound to anything I believe this is my problem.

So, here's my problem. I want to get distinct values into a combo box (I have already managed this bit) from a table, and if the user changes the combo box, find the first occurance of that record in a table called ChillOrders.

I am somewhat mystified why I cannot bind the combo box to the table (the field is called "ShipmentNumber"), and having written this sort of thing many times before in MSSQL I can't see why this cannot simply be done.

Anyone got any suggestions?

Answer : Using DoCMD.FindRecord getting runtime error 2162

Hello,

> (do I need these -- is this the problem?)

Yes, you need key fields. For single-table stuff, Access doesn't need them, but if you want to create editable multi-table queries, key fields are essential.

Example:
* table Customers has a primary (unique) index on the field CustomerID
* table Orders has a field CustomerID. This can be indexed for better performance, allowing duplicates.
* create a query on those tables
* use as link (and as only link) the one from Customers.CustomerID to Orders.CustomerID

The query is updatable.

Perhaps the problem is this: you do not only need key fields (or at least unique indexes), you also need to use these for the relationships. If you can't get it to work, simplify your tables to the bare minimum while still showing the problem, post here the table structures (field names, field types, indexes and keys), along with the query that results in a read-only datasheet (switch to SQL view, copy and paste here).

Hope this helps,
(°v°)
Random Solutions  
 
programming4us programming4us