Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cmdButton to open form in Data Entry mode Access 2K

Status
Not open for further replies.

Dreamboat

Instructor
Nov 7, 1999
4,881
US
Your wallpaper is prettier than ours in the MS Office forums!!

Need some help, obviously.

I create a cmdButton in a form that goes to open another form. I need to edit it so that it:

a) Opens the form in data entry view (I don't have to make TWO forms, right??) Current code:

Private Sub cmdAddNewPat_Click()
On Error GoTo Err_cmdAddNewPat_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmPatients"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdAddNewPat_Click:
Exit Sub

Err_cmdAddNewPat_Click:
MsgBox Err.Description
Resume Exit_cmdAddNewPat_Click

End Sub



b) Shows the form of the person in the CURRENT form. The current form shows the patient name, etc., and then has a subform for visits. I have a command button that, when clicked, I'd like it to open that Patient's record (PatID is the ID primary key for the patient). Current code shows all records.:

Private Sub cmdViewEditPatRecord_Click()
On Error GoTo Err_cmdViewEditPatRecord_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmPatients"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdViewEditPatRecord_Click:
Exit Sub

Err_cmdViewEditPatRecord_Click:
MsgBox Err.Description
Resume Exit_cmdViewEditPatRecord_Click

End Sub


I hugely appreciate the code, if possible. LOL Anne Troy
 
Here's the data entry:

Private Sub cmdAddNewPat_Click()
On Error GoTo Err_cmdAddNewPat_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmPatients"
DoCmd.OpenForm stDocName, , , , acFormAdd

Exit_cmdAddNewPat_Click:
Exit Sub

Err_cmdAddNewPat_Click:
MsgBox Err.Description
Resume Exit_cmdAddNewPat_Click

End Sub

Here's the filtered version:

Private Sub cmdViewEditPatRecord_Click()
On Error GoTo Err_cmdViewEditPatRecord_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmPatients"
stLinkCriteria = "[PatID]= ' " & Me![PatID] & " ' "

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdViewEditPatRecord_Click:
Exit Sub

Err_cmdViewEditPatRecord_Click:
MsgBox Err.Description
Resume Exit_cmdViewEditPatRecord_Click

End Sub

If the [PatID] field is numeric you can omit the single quotes from the stLinkCriteria string.


VBSlammer
redinvader3walking.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top