Reputation: 393
I got a main form which contains two coloumns which list a no/product. I had given vba code for product field click event to open preduct detail form with the selected product and it details to edit. I given code as below
Dim stDocName As String
Dim stLinkCriteria As String
stLinkCriteria = Me.Product
stDocName = "ProductDetail"
DoCmd.openform stDocName, , , "Product = " & stLinkCriteria
When I click the product its showing a input box and while enter the value its opening the product details with correct information.
I dont want to input the product name every time. I want this to work directly while clicking the product and should open it product details.
Please let me know how can do this ?
Upvotes: 0
Views: 6496
Reputation: 393
This code help me to fix the above problem
Forms!Frm.SetFocus
Const FORMNAME = "frm1"
Dim ctrl As Control
Dim strCriteria As String
On Error GoTo Err_Handler
Set ctrl = Me.ActiveControl
strCriteria = "[Product] = """ & ctrl & """"
DoCmd.OpenForm FORMNAME, WhereCondition:=strCriteria
Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here
Upvotes: 0
Reputation: 97101
If the [Product] field is text data type, enclose stLinkCriteria
with quotes in your OpenForm
statement.
DoCmd.OpenForm stDocName, , , "Product = '" & stLinkCriteria & "'"
Upvotes: 1