Event - OpenForm

L

Linda

I am trying to open a form based on an entry in a combo box. My select
statement for the comob box is:

SELECT VENDOR.vCODE, VENDOR.VENDOR FROM VENDOR ORDER BY VENDOR.VENDOR,
VENDOR.vCODE;

The event procedure is:

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Edit Vendor"

stLinkCriteria = "[VCODE]=" & Me![cboentercode]
DoCmd.OpenForm stDocName, , stLinkCriteria, acFormEdit


Exit_cmdOpenForm_Click:
Exit Sub

Err_cmdOpenForm_Click:
MsgBox Err.DESCRIPTION
Resume Exit_cmdOpenForm_Click

End Sub

When you click the command button, all the records show instead the chosen
record, based on the vendor code or vcode. I can't figure out where the
problem is. Can anyone help?
 
K

Klatuu

You just have strLinkCriteria in the wrong place. What you have is:
DoCmd.OpenForm stDocName, , stLinkCriteria, acFormEdit

It should be:
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit

The third argument is FilterName. It is the valid name for query in the
current database. What you want is WhereCondition which is what you have in
your code. One other note, however, your WhereCondition assumes [VCODE] is a
number. If it is a string, then it should be:
stLinkCriteria = "[VCODE]= '" & Me![cboentercode] & "'"
 
L

Linda

Klatuu - ty ty ty! Hope you have a great day!
--
Linda


Klatuu said:
You just have strLinkCriteria in the wrong place. What you have is:
DoCmd.OpenForm stDocName, , stLinkCriteria, acFormEdit

It should be:
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit

The third argument is FilterName. It is the valid name for query in the
current database. What you want is WhereCondition which is what you have in
your code. One other note, however, your WhereCondition assumes [VCODE] is a
number. If it is a string, then it should be:
stLinkCriteria = "[VCODE]= '" & Me![cboentercode] & "'"

Linda said:
I am trying to open a form based on an entry in a combo box. My select
statement for the comob box is:

SELECT VENDOR.vCODE, VENDOR.VENDOR FROM VENDOR ORDER BY VENDOR.VENDOR,
VENDOR.vCODE;

The event procedure is:

Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Edit Vendor"

stLinkCriteria = "[VCODE]=" & Me![cboentercode]
DoCmd.OpenForm stDocName, , stLinkCriteria, acFormEdit


Exit_cmdOpenForm_Click:
Exit Sub

Err_cmdOpenForm_Click:
MsgBox Err.DESCRIPTION
Resume Exit_cmdOpenForm_Click

End Sub

When you click the command button, all the records show instead the chosen
record, based on the vendor code or vcode. I can't figure out where the
problem is. Can anyone help?
 
Top