access 2010 form new record pre filled button

2019-09-13 05:25发布

I made a Access 2010 DB with 2 important tables: Patients and Samples. A Patient can have multiple Samples. In Patient I enter the Patient data In Samples I lookup some Patient data and add data for that Sample.

In splitform Samples I can search for all Samples of a Patient or select a Patient from a drop down button (lookup) What I want: I select a Sample from a Patient and then I want to create a new Sample for that Patient. When I create a button: AddRecord, all fields are empty, and I have to select the Patient again. Can I create a button to create a new Sample, where the Patient is allready filled in?

-Tried: OpenForm Where [Patient-nr]=[forms]![Patiens]![Patient-nr] but here I just filter and do not create a new record

-Tried: add Button, GoToRecord: new (used Use Controls Wizard)

-Tried: google....

2016-02-25, Added screenshots and extra information

1) first I open a Patient from my patients list

2) I click "Open Pt's samples (with PID)"button and get the samples list for that patient

Patients form and Samples form

3) I click "new sample" and get a blank sample form

Also the Relations for this DB

New sample and Relations in DB

What I would like is at 3) when [at 2)] I click "new sample" I get the samples form where "PID" (which is the Patient number), "Pt name" and "Date of birth" are pre-filled with the number of the patient I was just looking at. Now I have to look up the PID in my drop-down list in that field.

Update 2016-02-26

After Googling I found some hints and created:

Private Sub Command353_Click()  
On Error Resume Next  
DoCmd.RunCommand acCmdSelectRecord  
If (MacroError = 0) Then  
    DoCmd.RunCommand acCmdCopy  
End If  
If (MacroError = 0) Then  
    DoCmd.RunCommand acCmdRecordsGoToNew  
End If  
If (MacroError = 0) Then  
    DoCmd.RunCommand acCmdSelectRecord  
End If  
If (MacroError = 0) Then  
    DoCmd.RunCommand acCmdPaste  
End If  
Sample_nr = ""  
Sample_Date = ""  
Sample_Type = ""  
Sample_Volume = ""  
        {all other fields the same}
Me.Refresh  
If (MacroError <> 0) Then  
    Beep  
    MsgBox MacroError.Description, vbOKOnly, ""  
DoCmd.GoToRecord , , acLast  
End If  
End Sub

This works. Maybe not the nicest way, but... it does it's job

0条回答
登录 后发表回答