B
blanche
Howdy! I am trying to figure out how to pull up a record based on the
autonumber primary key. Mine is a database for tracking orders with each
order having an autonumber primary key (OrderID) and most having a
user-entered purchase order number (PurchaseOrderNumber). I have a search
form that allows me to search for records based on the vendor or item. On
this search form I have included a button that allows me to go directly to
the full version of the order (frmOrders). If I use my field
PurchaseOrderNumber and the following code the button works great:
Private Sub cmdGoToPO_Click()
On Error GoTo Err_cmdGoToPO_Click
Dim stDocName As String
Dim stLinkCriteria As String
If Not IsNull(Me.txtSearchPurchaseOrderNumber) Then
stDocName = "frmOrders"
stLinkCriteria = "[PurchaseOrderNumber]=" & "'" &
Me![PurchaseOrderNumber] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "No criteria", vbInformation, "Nothing to do."
End If
Exit_cmdGoToPO_Click:
Exit Sub
Err_cmdGoToPO_Click:
MsgBox Err.Description
Resume Exit_cmdGoToPO_Click
End Sub
However, not all of my orders have a purchase order number and I can't seem
to make this same type of event work to find records based on the OrderID
field (I've tried defining the stLinkCriteria as an integer, but that didn't
do the job). I'm not very experienced writing code. Any help would be
greatly appreciated. thanks
autonumber primary key. Mine is a database for tracking orders with each
order having an autonumber primary key (OrderID) and most having a
user-entered purchase order number (PurchaseOrderNumber). I have a search
form that allows me to search for records based on the vendor or item. On
this search form I have included a button that allows me to go directly to
the full version of the order (frmOrders). If I use my field
PurchaseOrderNumber and the following code the button works great:
Private Sub cmdGoToPO_Click()
On Error GoTo Err_cmdGoToPO_Click
Dim stDocName As String
Dim stLinkCriteria As String
If Not IsNull(Me.txtSearchPurchaseOrderNumber) Then
stDocName = "frmOrders"
stLinkCriteria = "[PurchaseOrderNumber]=" & "'" &
Me![PurchaseOrderNumber] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "No criteria", vbInformation, "Nothing to do."
End If
Exit_cmdGoToPO_Click:
Exit Sub
Err_cmdGoToPO_Click:
MsgBox Err.Description
Resume Exit_cmdGoToPO_Click
End Sub
However, not all of my orders have a purchase order number and I can't seem
to make this same type of event work to find records based on the OrderID
field (I've tried defining the stLinkCriteria as an integer, but that didn't
do the job). I'm not very experienced writing code. Any help would be
greatly appreciated. thanks