C
Ceebaby via AccessMonster.com
Hi Folks
This has been puzzling me. I frequently use the same code over and over again
on various combo boxes stored within my database on their notinlist event.
Heres what I use
Private Sub cmbType_NotInList(NewData As String, Response As Integer)
Dim rst As DAO.Recordset
If MsgBox(NewData & "... not in list, do you want to add it?", vbOKCancel,
"DIS87") = vbOK Then
Set rst = CurrentDb.OpenRecordset("QRY ListEnforcement") -
With rst
.AddNew
.Fields("Enforcement") = NewData
.Update
.CLOSE
End With
Set rst = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
Works like a charm'
However, I would like to create a global/public proceedure/function for the
notinlist code above where I could just insert the names of the tables for
the recordset and fields names which the combo list will update. Basically I
am trying to streammline the code within each form. For instance, I have a
form that has 5 combo boxes and each combo box has the above code for the
notinlist event.
I have had a bash with
Public Sub Getlist(rstType,NewFieldType as string)
Dim rst As DAO.Recordset
If MsgBox(NewData & "... not in list, do you want to add it?", vbOKCancel,
"DIS87") = vbOK Then
Set rst = CurrentDb.OpenRecordset(rstType)
With rst
.AddNew
.Fields(NewFieldType) = NewData
.Update
.CLOSE
End With
Set rst = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
then would call it on the notinlist event
call getList
rstType ="Some Table"
NewfieldType ="Some table fieldname" field to be updated in the combo box
This does not work - i think I may be at least at the starting line here if
nothing else
Is this possible at all? or should I just resign myself to repeating the same
code over and over again for each combo. I hope this makes sense.
As ever any help or guidance is always much appreciated.
Cheers
Ceebaby
London
This has been puzzling me. I frequently use the same code over and over again
on various combo boxes stored within my database on their notinlist event.
Heres what I use
Private Sub cmbType_NotInList(NewData As String, Response As Integer)
Dim rst As DAO.Recordset
If MsgBox(NewData & "... not in list, do you want to add it?", vbOKCancel,
"DIS87") = vbOK Then
Set rst = CurrentDb.OpenRecordset("QRY ListEnforcement") -
With rst
.AddNew
.Fields("Enforcement") = NewData
.Update
.CLOSE
End With
Set rst = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
Works like a charm'
However, I would like to create a global/public proceedure/function for the
notinlist code above where I could just insert the names of the tables for
the recordset and fields names which the combo list will update. Basically I
am trying to streammline the code within each form. For instance, I have a
form that has 5 combo boxes and each combo box has the above code for the
notinlist event.
I have had a bash with
Public Sub Getlist(rstType,NewFieldType as string)
Dim rst As DAO.Recordset
If MsgBox(NewData & "... not in list, do you want to add it?", vbOKCancel,
"DIS87") = vbOK Then
Set rst = CurrentDb.OpenRecordset(rstType)
With rst
.AddNew
.Fields(NewFieldType) = NewData
.Update
.CLOSE
End With
Set rst = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
then would call it on the notinlist event
call getList
rstType ="Some Table"
NewfieldType ="Some table fieldname" field to be updated in the combo box
This does not work - i think I may be at least at the starting line here if
nothing else
Is this possible at all? or should I just resign myself to repeating the same
code over and over again for each combo. I hope this makes sense.
As ever any help or guidance is always much appreciated.
Cheers
Ceebaby
London