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
NadiaRashidAsked:
Who is Participating?
 
mbizupCommented:
Try this:

DoCmd.OpenForm stDocName, , , "PatientID = " & Me.pkey
                                                                                       ^--- Make sure this is the name of the field/control onyour form.
0
 
mbizupCommented:
The code would look like this:

Docmd.OpenForm "MyEditForm",,,"[pkfield] = " & me.P_key
0
 
NadiaRashidAuthor Commented:
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! :)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
mbizupCommented:
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.
0
 
NadiaRashidAuthor Commented:
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

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

Table Name:  ?
Field Name:  ?
0
 
NadiaRashidAuthor Commented:
Table Name = PatientTable
FeildName = PatientID
0
 
NadiaRashidAuthor Commented:
YESS! it works! thanks so much :)
0
 
mbizupCommented:
Glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.