Autofill a new Record in a 2nd form from a different form

A

Axess08

Due to the nature of the research, I have a complex database that stores
information for what should be several seperate databases for seperate
research studies' information. Because they have information that is linked
(and also for easier non-repetitive data entry), the doctors have requested
that it be just 1 database.

All that aside, this database has 1 main "patient identification" table that
links all
tables in the database by the Patient Identification field "Pt_ID_#". (I
hate spaces, but it has been requested to be able to track the fields and
tables).

I have forms for each of these tables and again due to the nature of the
database, i cannot have a form, subform (i.e. parent child) design because of
the number of forms, so I have buttons to make the data entry easier.

I want to have the "Pt ID #" field to be autofilled in every subsequent
form. Basically I want to be able to enter the "Pt ID #" manually in the Main
form and then press a button that links to another form which opens a new
record for that patient and autofills just the "Pt ID #" field based on my
entry. Unfortunately, because I do not have the form/subform set up this has
created the problem of not being able to simply autofill the "Pt ID #" field.
I know this can be resolved simply through coding, however, I can't get it to
work. Is it possible that I am missing something? I have tried the following:


On Click (Button on the Main form):

Private Sub StudiesLink_Click()
DoCmd.OpenForm "Research Studies Table Form", , , ,acFormAdd , ,Me.[Pt ID #]
On Error GoTo Err_StudiesLink_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Research Studies Table Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_StudiesLink_Click:
Exit Sub

Err_StudiesLink_Click:
MsgBox Err.Description
Resume Exit_StudiesLink_Click

End Sub
 
S

Steve Sanford

All that aside, this database has 1 main "patient identification" table that
links all
tables in the database by the Patient Identification field "Pt_ID_#". (I

Having spaces (and special characters ie #) will just cause you headaches
later on. "PtIDNum" or "Pt_ID_Num" would be better....
hate spaces, but it has been requested to be able to track the fields and
tables).

Who will be "able to track the fields and tables"??? Only the programmer
should be messing arouond in the guts (pun intended <grin> I couldn't resist)
of the MDB!!



This is how I would do it.... !!!! Air code - untested !!!!!

'On Click (Button on the Main form):
'---------------------------
Private Sub StudiesLink_Click()
On Error GoTo Err_StudiesLink_Click

Dim stDocName As String

stDocName = "Research Studies Table Form"
DoCmd.OpenForm "stDocName ", , , ,acFormAdd , ,Me.[Pt ID #]

Exit_StudiesLink_Click:
Exit Sub

Err_StudiesLink_Click:
MsgBox Err.Description
Resume Exit_StudiesLink_Click

End Sub
'---------------------------


Then in the Form load event of the form "Research Studies Table Form", enter:

'---------------------------
Private Sub Form_Load()
'Use this version if the ID is a number
If Len(Me.OpenArgs) > 0 Then

Me.PtIDNum = Me.OpenArgs '<< change "PtIDNum" to your field name

End If
End Sub
'---------------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Axess08 said:
Due to the nature of the research, I have a complex database that stores
information for what should be several seperate databases for seperate
research studies' information. Because they have information that is linked
(and also for easier non-repetitive data entry), the doctors have requested
that it be just 1 database.

All that aside, this database has 1 main "patient identification" table that
links all
tables in the database by the Patient Identification field "Pt_ID_#". (I
hate spaces, but it has been requested to be able to track the fields and
tables).

I have forms for each of these tables and again due to the nature of the
database, i cannot have a form, subform (i.e. parent child) design because of
the number of forms, so I have buttons to make the data entry easier.

I want to have the "Pt ID #" field to be autofilled in every subsequent
form. Basically I want to be able to enter the "Pt ID #" manually in the Main
form and then press a button that links to another form which opens a new
record for that patient and autofills just the "Pt ID #" field based on my
entry. Unfortunately, because I do not have the form/subform set up this has
created the problem of not being able to simply autofill the "Pt ID #" field.
I know this can be resolved simply through coding, however, I can't get it to
work. Is it possible that I am missing something? I have tried the following:


On Click (Button on the Main form):

Private Sub StudiesLink_Click()
DoCmd.OpenForm "Research Studies Table Form", , , ,acFormAdd , ,Me.[Pt ID #]
On Error GoTo Err_StudiesLink_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Research Studies Table Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_StudiesLink_Click:
Exit Sub

Err_StudiesLink_Click:
MsgBox Err.Description
Resume Exit_StudiesLink_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top