G
Guest
I have a form with a combo box in the header which is used to select a
sampleID, then based on the selection, the form will go to the specified
record and display the info for that record. This works fine, but when I
first open the form although the combo box is empty (until I make a
selection), the other fields have data displayed in them for a certain
record. It is not the first record in the list, nor is it the last record
viewed. It opens to the same record everytime, even if I move to another
record before closing the form.
There is no default value set for any of the controls, and absolutely no
code in the Form Open events, or any other Form events. I've tried setting
all the controls = "" or to null, but I get an error saying I can't set value
for these controls. I wanted all the fields to be empty upon first opening
the form, but at this point I'd settle for getting it to display all the info
for the first record as default. I can get the combo box to display the 1st
item as it's default value, but the rest of the form still displays details
for another record, I can't figure out why it's displaying that record and
how to get rid of it. This is all the code I have in the form:
Private Sub cboSampleID_AfterUpdate()
' Find the record that matches the Sample ID selected in the listbox.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Sample ID] = '" & Me![cboSampleID] & "'"
Me.Bookmark = rs.Bookmark
cmdViewSubtest.SetFocus
End Sub
Private Sub cboSampleID_NotInList(NewData As String, Response As Integer)
MsgBox "The Sample ID you entered could not be found in the database",
vbOKOnly, "Sample ID Not Found!"
Response = acDataErrDisplay
End Sub
Private Sub cmdViewSubtest_Click()
On Error GoTo Err_cmdViewSubtest_Click
DoCmd.OpenForm "fsubSampleSubTestData", acNormal, , [Sample ID] = _
Forms![frmSampleData]![cboSampleID], acFormReadOnly,
acWindowNormal
Exit_cmdViewSubtest_Click:
Exit Sub
Err_cmdViewSubtest_Click:
MsgBox Err.Description
Resume Exit_cmdViewSubtest_Click
End Sub
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
DoCmd.Close
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub
sampleID, then based on the selection, the form will go to the specified
record and display the info for that record. This works fine, but when I
first open the form although the combo box is empty (until I make a
selection), the other fields have data displayed in them for a certain
record. It is not the first record in the list, nor is it the last record
viewed. It opens to the same record everytime, even if I move to another
record before closing the form.
There is no default value set for any of the controls, and absolutely no
code in the Form Open events, or any other Form events. I've tried setting
all the controls = "" or to null, but I get an error saying I can't set value
for these controls. I wanted all the fields to be empty upon first opening
the form, but at this point I'd settle for getting it to display all the info
for the first record as default. I can get the combo box to display the 1st
item as it's default value, but the rest of the form still displays details
for another record, I can't figure out why it's displaying that record and
how to get rid of it. This is all the code I have in the form:
Private Sub cboSampleID_AfterUpdate()
' Find the record that matches the Sample ID selected in the listbox.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Sample ID] = '" & Me![cboSampleID] & "'"
Me.Bookmark = rs.Bookmark
cmdViewSubtest.SetFocus
End Sub
Private Sub cboSampleID_NotInList(NewData As String, Response As Integer)
MsgBox "The Sample ID you entered could not be found in the database",
vbOKOnly, "Sample ID Not Found!"
Response = acDataErrDisplay
End Sub
Private Sub cmdViewSubtest_Click()
On Error GoTo Err_cmdViewSubtest_Click
DoCmd.OpenForm "fsubSampleSubTestData", acNormal, , [Sample ID] = _
Forms![frmSampleData]![cboSampleID], acFormReadOnly,
acWindowNormal
Exit_cmdViewSubtest_Click:
Exit Sub
Err_cmdViewSubtest_Click:
MsgBox Err.Description
Resume Exit_cmdViewSubtest_Click
End Sub
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
DoCmd.Close
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub