DoCmd.OpenForm Method

hhzyousafi

Registered User.
Local time
Tomorrow, 03:14
Joined
Nov 18, 2013
Messages
74
I have searched this forum to make sure my syntax was correct before posting; however despite, in my opinion, having correct syntax I am unable to open a form based on a specific record. I have a form called "frmBasicEmployeeInformation". I have another form, the form is called "frmBasicEmployeeInformationSearch", that is based on a query that is based on the table "tblBasicEmployeeInformation". The form "frmBasicEmployeeInformation" is also based on the table "tblBasicEmployeeInformation".

The form "frmBasicEmployeeInformation" has a field called txttblBasicEmployeeInformationID and the form "frmBasicEmployeeInformationSearch" has a field called "tblBasicEmployeeInformationID". Here is the syntax I am using on the double click event on the form "frmBasicEmployeeInformationSearch":

Private Sub FirstName_DblClick(Cancel As Integer)

DoCmd.OpenForm "frmBasicEmployeeInformation", acNormal, , "txttblBasicEmployeeInformationID=" & Me.tblBasicEmployeeInformationID.Value

End Sub​

I have tried removing the ".value" in the last part of the code; however that has done nothing for me either. The form has opened; however there is no data showing in the form. What am I missing here?
 
Show us the underlying table for frmBasicEmployeeInformation (a pic from the relationships window)
 
No relationships for this particular table; however here is a screenshot of all of the fields in the "Design View" of this table.
 

Attachments

  • tblBasicEmployeeInformation Screenshot.jpg
    tblBasicEmployeeInformation Screenshot.jpg
    85.2 KB · Views: 130
  1. What is the value of "Me.tblBasicEmployeeInformationID.Value" in the Sub FirstName_DblClick?
  2. Are you sure the recordsource for the form has a field name called "txttblBasicEmployeeInformationID"?
 
Hi JHB,

The value of "Me.tblBasicEmployeeInformationID.Value" is a numeric value (i.e. 23, 47, 34, etc.,) whereas this value can be obtained by either including the ".value" at the end or by removing the ".value" altogether.

I presume you are referring to the recordsource of the form I am trying to open? No the recordsource does not have a field named "txttblBasicEmployeeInformationID"; however it does have a field named "tblBasicEmployeeInformationID" and I have tried that in the code as well and that doesn't work either.

Regards,

Zohair Yousafi
 
Post a stripped version of your database with some sample data, (zip it).
 
Hi JHB,

I think I have figured it out. The syntax is correct; however the form I was opening had the "DataEntry" property set to "Yes". I changed it to "No" and it is working as expected now. Thank you for your help.

Regards,

Zohair Yousafi
 
Try this:
DoCmd.OpenForm "frmBasicEmployeeInformation", acNormal, , "tblBasicEmployeeInformationID = " & Me.tblBasicEmployeeInformationID
 
Hi Mihail,

Thank you for the response; however please note that it wasn't a syntax error. The issue was that I had set the DataEntry property of the form I was opening up to "Yes" and that didn't allow the form to open up the record I wanted to edit. I changed the property to "No" and it worked like a charm.

Regards,

Zohair Yousafi
 
Take a look to the posts times.
That mean that I write in the (almost) same time as you.
It is why I don't know that you already solved this (congratulations ! )
 

Users who are viewing this thread

Back
Top Bottom