Home > Back-end >  Problems with .FindFirst method in VBA for MS ACCESS
Problems with .FindFirst method in VBA for MS ACCESS

Time:09-03

I'm new to VBA and ACCESS and have come across a problem, below is a brief description. I have created a table named tblProduct with 3 fields, Product_ID (short text), Product_Name (short text), Sale_Unit (short text), Product_ID is primary key. Then there is a form name frm_Product, with cboProductID as combo box, with the row saource set to:

SELECT tblProduct.ID, tblProduct.Product_Name, tblProduct.Sale_Unit
FROM tblProduct
ORDER BY tblProduct.Product_Name;

Its bound column set to 1, column count to 3, column width to 0cm;4cm;2cm, there are then 2 textboxes, txtProduct_Name and txtSale_Unit. Then I wrote the following code fro the AfterUpdate event of cboProductID:

Private Sub cboProductID_AfterUpdate()
    
    Set rs1 = CurrentDb.OpenRecordset("tblProduct", dbOpenDynaset, dbSeeChanges)
    rs1.FindFirst "ID = '" & "Me.cboProductID.Column(0)" '"
    txtProduct_Name = rs1!Product_Name
    txtSale_Unit = rs1!Sale_Unit
    
End Sub

The code doesn't work, it stopped at the .FindFirst method, can someone help me out? Thank you in advance.

CodePudding user response:

Try this:

rs1.FindFirst "ID = '" & Me.cboProductID.Column(0) & "'"

if you put quotes around that expression, then you wind up search for a id of Me.cboproductID.Column(0), and I don't think that is the "id" your looking for.

CodePudding user response:

Try this instead : Remove the Quotes around me.cboProdtID.Column(0)

  • Related