E
Ernie
I am a newbe at VB and have a couple of questions I hope someone can answer.
I have a combo box that will prompt to open a form to add a new record for
an item not in the list and it seems to work fine.
Question 1. Is there a way to populate the field in the new record form with
the data previously entered in combo box? The new record form opens in
dialog which stops the code from running. It will work if I open the form in
normal mode but error msgs are created because the new data hasn't been
entered yet.
Question 2. After entering the new data and closing the add record form, I
can select the new record if I scroll to the bottom of the list. Is there
any way to have that record already selected when I return to this form from
the add new record form?
Here is the code I am using so far:
Private Sub cbotblvinID_NotInList(NewData As String, Response As Integer)
On Error GoTo ErrHandler
MsgBox "Please double-click this field" & vbCrLf & _
"to add a new VIN to the list.", _
vbInformation + vbOKOnly, "No Matching Record"
Response = acDataErrContinue
Exit Sub
ErrHandler:
MsgBox "Error in cbotblvinID_NotInList( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.description
Err.Clear
End Sub
Private Sub cbotblvinID_DblClick(Cancel As Integer)
On Error GoTo ErrHandler
Dim ntblvinID As Long
If (IsNull(Me!cbotblvinID)) Then
Me!cbotblvinID.Text = ""
Else
ntblvinID = Me!cbotblvinID
Me!cbotblvinID = Null
End If
DoCmd.OpenForm "tblvin", , , , , acDialog, "New"
Me!cbotblvinID.Requery ' Get all records.
If (ntblvinID <> 0) Then
Me!cbotblvinID = ntblvinID ' Reset to original row.
End If
Exit Sub
ErrHandler:
MsgBox "Error in cbotblvinID_DblClick( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.description
Err.Clear
End Sub
Private Sub Form_Load()
On Error GoTo ErrHandler
If ((Me.OpenArgs = "New") And Not IsNull(Me!tblvinID)) Then
DoCmd.GoToRecord , , acNewRec
End If
Exit Sub
ErrHandler:
MsgBox "Error in Form_Load( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.description
Err.Clear
End Sub
Thanks in advance for your reply!
I have a combo box that will prompt to open a form to add a new record for
an item not in the list and it seems to work fine.
Question 1. Is there a way to populate the field in the new record form with
the data previously entered in combo box? The new record form opens in
dialog which stops the code from running. It will work if I open the form in
normal mode but error msgs are created because the new data hasn't been
entered yet.
Question 2. After entering the new data and closing the add record form, I
can select the new record if I scroll to the bottom of the list. Is there
any way to have that record already selected when I return to this form from
the add new record form?
Here is the code I am using so far:
Private Sub cbotblvinID_NotInList(NewData As String, Response As Integer)
On Error GoTo ErrHandler
MsgBox "Please double-click this field" & vbCrLf & _
"to add a new VIN to the list.", _
vbInformation + vbOKOnly, "No Matching Record"
Response = acDataErrContinue
Exit Sub
ErrHandler:
MsgBox "Error in cbotblvinID_NotInList( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.description
Err.Clear
End Sub
Private Sub cbotblvinID_DblClick(Cancel As Integer)
On Error GoTo ErrHandler
Dim ntblvinID As Long
If (IsNull(Me!cbotblvinID)) Then
Me!cbotblvinID.Text = ""
Else
ntblvinID = Me!cbotblvinID
Me!cbotblvinID = Null
End If
DoCmd.OpenForm "tblvin", , , , , acDialog, "New"
Me!cbotblvinID.Requery ' Get all records.
If (ntblvinID <> 0) Then
Me!cbotblvinID = ntblvinID ' Reset to original row.
End If
Exit Sub
ErrHandler:
MsgBox "Error in cbotblvinID_DblClick( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.description
Err.Clear
End Sub
Private Sub Form_Load()
On Error GoTo ErrHandler
If ((Me.OpenArgs = "New") And Not IsNull(Me!tblvinID)) Then
DoCmd.GoToRecord , , acNewRec
End If
Exit Sub
ErrHandler:
MsgBox "Error in Form_Load( ) in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.description
Err.Clear
End Sub
Thanks in advance for your reply!