Using a combobox to check if record exist then populate form

Anonymous
2014-09-10T22:04:07+00:00

So I have posted my question to several forums and have had some good response but no resolution. I am quite new to Access 2010 and VBA. So here is my issue. I have built a Navigation Page with several forms(bound) so my users can enter data and saved to a table. What I have is a room delay form to capture information for a  medical procedure and to document when a delay occurs. My TABLE is tblDelay and my form is FormDelay.

On occasion my users will enter some information and save and close the form. Then will need to edit the record. I have attempted to create a Assession Num Search in the form header based on someone's recommendation using this code:

Private Sub cboAssessionSearch_AfterUpdate()

Const MESSAGETEXT = "This Assession Number already exists."

 If Not IsNull(DLookup("AssessionNumber", "tblDelay", "AssessionNumber=" & Me.AssessionNumber)) Then

 MsgBox MESSAGETEXT, vbExclamation, "Invalid Operation"

 'code to filter form for the existing record

 Me.Filter = "AssessionNumber=" & Me.AssessionNumber

 Me.FilterOn = True

 Else

 'code to move to new record row

 DoCmd.GoToRecord , , acNewRec

 End If

End Sub

I can find the populated Assession Numbers in the combobox but I need to have certain criteria. If the assession number exists the populate the form with the record fields so an edit can be made and an update to the record made in the table. If the Assession Number does not exist leave the form blank so a new record can be entered. Nothing happens when I select a Assession Number and hit enter. No error message indication record exists or not.

I have built several buttons (Add, Edit, Delate, Clear, and Close) in the header. If a assession Numbers need edited and updated then repopulate the form with the appropriate record found using the Assession Num Search combobox, If no record found, the enter new information.

Table Field Names

dept, Rm_Num, MRN, AssessionNumber, CaseNumber (Not inclusive of all fields, If I can get these filed to populate I can get the rest)

Form Names

cboDept, cboRmNum, txtMRN, txtAssessionNumber, txtCaseNumber (Not inclusive of all boxes)

Bound Form to table

Any help finding resolution would be of GREAT HELP!!! 

Thank you in advance,

Kerry

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

51 answers

Sort by: Most helpful
  1. Anonymous
    2014-09-17T23:20:35+00:00

    Ken,

    I have uploaded the database front and backend to my OneDrive. I removed all sensitive data. This was my first use of this file sharing site. Hope it works.

    https://onedrive.live.com/redir?resid=EE5D341CCB08B8ED%21448

    Thanks for your help.

    Kerry

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-09-17T21:57:23+00:00

    Assuming the control's RecordSource is:

    SELECT ID, AssessionNumber, 1 As SortColumn

    FROM tblDelay

    UNION

    SELECT 0, "<New Record>", 0

    FROM tblDelay

    ORDER BY SortColumn, AssessionNumber;

    at first sight I see nothing which would cause the behaviour you are experiencing.  If you can post a copy of the file, converted down to Access 2007 format, and stripped of all sensitive data, to OneDrive or a similar file-sharing site, then I can attempt to debug it.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2014-09-17T18:34:13+00:00

    Thank you for the reply, I double checked these properties and the are as you requested.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-09-17T17:05:46+00:00

    Are you sure you have the combo box's other properties correct?

    BoundColumn:    1

    ColumnCount:     2

    ColumnWidths:    0cm

    If your units of measurement are imperial rather than metric Access will automatically convert the unit of the last one to inches.  The important thing is that the dimension is zero to hide the first column.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2014-09-17T16:29:51+00:00

    Here is where I am at. When I input a new number into the combobox I get strMessage = "Add " & NewData & " to list?" and when selecting Yes moves the focus to the cboDept to initiated data input on a new record. Next when I select <New Record> from the combobox the focus moves to txtAssessionNumber. I will change this focus to match the other. Both of these appear to be working.

    What appears not to be working is when I input a known Assession Number into the combobox I get the Warning Message: No matching record. I have in my table fields ID (Primary Key, Indexed Yes (No Duplicates)), MRN (Indexed Yes (Duplicates OK)), and AssessionNumber (Indexed Yes (No Duplicates)). I currently have this code in my cboGoToAssession event procedure:

    Private Sub cboGotoAssession_AfterUpdate()

        Const MESSAGETEXT = "No matching record"

        Dim ctrl As Control

        Set ctrl = Me.ActiveControl

        If Not IsNull(ctrl) Then

            If ctrl = 0 Then

                ' go to new record and move focus to Assession control

               ' DoCmd.GoToRecord acForm, Me.Name, acNewRec (Tried but did not work)

                DoCmd.GoToRecord , , acNewRec

                Me.txtAssessionNumber.SetFocus

            Else

                With Me.RecordsetClone

                    .FindFirst "ID = " & ctrl

                    If Not .NoMatch Then

                        ' go to record by synchronizing bookmarks

                        Me.Bookmark = .Bookmark

                    Else

                        MsgBox MESSAGETEXT, vbInformation, "Warning"

                    End If

                End With

            End If

        End If

    End Sub

    Private Sub cboGotoAssession_NotInList(NewData As String, Response As Integer)

        Dim ctrl As Control

        Dim strMessage As String

        Set ctrl = Me.ActiveControl

        strMessage = "Add " & NewData & " to list?"

        'if user confirms insert, move form to new record

        ' and insert values into AssessionNumber control

        If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then

            Response = acDataErrContinue

            ctrl.Undo

            DoCmd.GoToRecord , , acNewRec

            Me.cboGoToAssession = NewData

        Else

            Response = acDataErrContinue

            ctrl.Undo

        End If

    End Sub

    Can you see anything I have done wrong when I input a known Assession Number into the cboGoToAssession what would make a No Matching record? I have tried I think every recommendation you have made. This is the only piece not working. I have reviewed your findrecord example over and over. See no difference in what I have attempted.

    Sorry for the continued questions, I am just about there.

    Thanks again for all your help.

    Kerry

    Was this answer helpful?

    0 comments No comments