link append query to combobox

  • Thread starter Kevin via AccessMonster.com
  • Start date
K

Kevin via AccessMonster.com

I have a form (tester) that contains two unbound comboboxes. The first,
cboMRSearchChart looks up a specific ID number (text datatype) for a patient,
and the second (cboDOVSearchChart), displays the dates of visit associated
with that ID number. The two fields are from the table "Patient Visits,"
where an autonumber Chart ID serves as the primary key. The selection of a
date updates a subform (sbfPatientVisits), which is related to the mainform
via Chart ID number. The column with Chart ID is present in the Date of Visit
combobox, but is hidden from view.

In the NotInList event of the DOV search combobox, I would like to run an
append query that will add the new patient ID number/date of visit
combination to the "Patient Visits" table. Ideally, this would also update
the subform to display the new entry for date of visit and would allow users
to add information to the rest of the fields in the subform.

I have almost no experience with VBA, but I'm wading my way through it.
Here's the current code that I've adopted from another post:

Private Sub cboDOVSearchChart_NotInList(NewData As String, Response As
Integer)
Response = acDataErrContinue
Call Date_Not_Found(NewData)
End Sub

Public Sub Date_Not_Found(NewData)
Dim ans As Variant

' add date
gbl_exit_name = False

ans = MsgBox("The date you entered was not found. Do you want to add a new
date?", _
vbYesNo, "Add New Date?")

If ans = vbNo Then
Me.cboDOVSearchChart = Null
DoCmd.GoToControl "cboMRSearchChart"
GoTo exit_it
End If

' add date
If ans = vbYes Then
DoCmd.OpenQuery "qryAddVisit"

Me.Detail.Visible = True
Me.sbfPatientVisits.Visible = True
[Forms]![sbfPatientVisits].[DateofVisit].SetFocus
End If
exit_it:

End Sub

The query SQL is as follows:
INSERT INTO [Patient Visits] ( [Medical Record Number], [Date of Visit] )
SELECT Forms!tester!cboMRSearchChart, Forms!tester!cboDOVSearchChart AS
Expr1;

Everything seems to be working well, however, running the query only adds the
medical record number (with a new Autonumber) to the Patient Visits table.
Also, the subform appears blank (not entries in any of the fields, including
date of visit). Any advice that could help me straighten this out would be
greatly appreciated.

Kevin
 

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

Similar Threads


Top