Link to home
Start Free TrialLog in
Avatar of NadiaRashid
NadiaRashid

asked on

Edit button to load form using selected record

Hello Experts,

I'm working on an MS 200 db, and I have an advanced search which feeds into a display form.
I want to add an edit button next to each record, which captures it's p_key and loads an edit person form for exactly the record the user selected the edit for. How do i go about doing that? Please may you post some demo code for me or forward me to some tutorial i may get a clue from? Any help would be highly appreciated!

Thanks :)
Nadia
Avatar of mbizup
mbizup
Flag of Kazakhstan image

The code would look like this:

Docmd.OpenForm "MyEditForm",,,"[pkfield] = " & me.P_key
Avatar of NadiaRashid
NadiaRashid

ASKER

Hi mbizup,

I tried this code in my edit button :

Private Sub btnEdit_Click()
DoCmd.OpenForm "MyForm", , , "[pkey.Table.] = " & Me.pkey
End Sub

But when i run it in my form it does nothing. Any suggestions?? By the way thank for your response! :)
Just nothing... no form opening, no errors?

Double check that you are using the correct names for your application:

DoCmd.OpenForm "MyForm", , , "[pkey.Table.] = " & Me.pkey
                                ^--- The form to be opened              ^--- The control or field containing the ID

Then make sure that the code is "tied" to the event:
- In your command button's property sheet, click the "..." next to On click under the Events tab.  This should bring up the code you typed in.  If the code was not tied to the event previously, it should be now.

If this does not help, can you post a sample of your db at www.ee-stuff.com ?   Use youe EE username and password.  The upload should be a zipped file, no more than 4 meg.  Post the URL that ee-stuff provides you in your next comment here.
The code is tied to the event, I performed the check you advised. I made a couple of edits in the form, so now it give me the following error:

Invalid bracketing of name "[pkey.Table]"

and here is my code:

Private Sub btnEdit_Click()
On Error GoTo Err_btnEdit_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Table"
    DoCmd.OpenForm stDocName, , , "[pkey.Table] = " & Me.pkey
   
Exit_btnEdit_Click:
    Exit Sub

Err_btnEdit_Click:
    MsgBox Err.Description
    Resume Exit_btnEdit_Click

End Sub

What is the exact name of the field you are working with?  Let me know, in this format:

Table Name:  ?
Field Name:  ?
Table Name = PatientTable
FeildName = PatientID
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
YESS! it works! thanks so much :)
Glad to help :-)