problem linking forms (1 Viewer)

S

shane

Guest
I have several tables, all containing the common field 'patient id'. My form opens by asking the user to input the patient id. It then displays the specific patient info. I need to add control buttons to this form to open several other forms for input. The buttons I currently have open the forms but, when data is saved to tables, it does not save the patient id to 'each' table, so I can't link them to print a report. If I make a form with subforms, the patient id is input to each respective table. But I need buttons! I know very little VB so any help would be appreciated.
 

Sharda

New member
Local time
Today, 08:48
Joined
Feb 29, 2000
Messages
5
I had the same problem some time back. This is how I solved the problem. I wrote a VBA code
Open rst as a recordset
set rst as recordset
set dbs as database
dbs = currentdb()
rst = dbs.openrecordset("<table name">
With rst
.AddNew
!patientid = Me.txtpatientid
.Update
.Close
End With
end with
I created and rst for every table that needed to be updated.
I would really like to know, if there is an easier solution.
 
S

shane

Guest
Thanks Sharda but I still need help. Is there any way you could be more specific; I tried your code many different times and keep getting errors. For example, where you say "as recordset", it requires an =. I'd really appreciate any additional comments. Thanks again.
 

Carol

Registered User.
Local time
Today, 08:48
Joined
Jan 15, 2000
Messages
280
Here is a simple way to achieve what you want. On your command buttons for the various forms on the "On Click" event, insert this code:

Private Sub Open_FormName_Click()
On Error GoTo Err_Open_FormName_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MainFormName"

stLinkCriteria = "[patient id]=" & "'" & Me![patient id] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open_FormName_Click:
Exit Sub

Err_Open_FormName_Detail_Click:
MsgBox Err.Description
Resume Exit_Open_FormName_Click

End Sub


Where I have stated FormName that represents the new form that you wish to open. MainFormName is the form with the command buttons on it.

Hope this helps.
 

Users who are viewing this thread

Top Bottom