CAN WE ADD 2 DATA VALUES TO 2 FIELDS USING NOT IN LIST EVENT (1 Viewer)

Ashfaque

Student
Local time
Today, 19:59
Joined
Sep 6, 2004
Messages
894
Hi,

I have this below code to add the data that is not in the tbl but it is for single field. Is it possible to make it for one other field in the same table. I have Added another field name in table Called SectionName. I want the code to ask me SectionName also while adding newdata in. Becuase my table have new field now which is SectionName

Private Sub CboDept_NotInList(NewData As String, Response As Integer)
Dim NewHRSQL As String
Dim P As Integer
Dim msg As String

'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub

msg = "'" & NewData & "' Department is not in the list." & vbCr & vbCr
msg = msg & "Do you want to add it?"

P = MsgBox(msg, vbQuestion + vbYesNo, "New Destination...")
If P = vbYes Then
NewHRSQL = "Insert Into T_Dept ([CDeptarments]) values ('" & NewData & "')"
CurrentDb.Execute NewHRSQL, dbFailOnError
Response = acDataErrAdded

Else
Response = acDataErrContinue
End If
End Sub

Is it possible or I have to place another combo and write separate similar code?

Please advise.
Thanks in advance.
Ashfaque
 

Dreamweaver

Well-known member
Local time
Today, 14:29
Joined
Nov 28, 2005
Messages
2,466
Download The Code Library There are a number of combobox functions including a function that allows for a number of additional items.

Regards mick
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:29
Joined
May 7, 2009
Messages
19,169
Code:
Private Sub CboDept_NotInList(NewData As String, Response As Integer)
Dim NewHRSQL As String
Dim P As Integer
Dim msg As String
Dim strSectionName as string

'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub

msg = "'" & NewData & "' Department is not in the list." & vbCr & vbCr
msg = msg & "Do you want to add it?"

P = MsgBox(msg, vbQuestion + vbYesNo, "New Destination...")
If P = vbYes Then
LoopHere:
    strSectionName = InputBox("Please enter the Section Name")
    If len(strSectionName)<1 then
        If Msgbox("You have not supplied the Section Name. Do you want to enter it now?", vbQuestion + vbYesNo) = vbYes Then
            GoTo LoopHere
        Else
            Response = acDataErrContinue
        End If
    Else
        NewHRSQL = "Insert Into T_Dept ([CDeptarments], [SectionName]) values ('" & NewData & "','" & strSectionName & "')"
        CurrentDb.Execute NewHRSQL, dbFailOnError
        Response = acDataErrAdded
    End If
Else
    Response = acDataErrContinue
End If
End Sub
 

Ashfaque

Student
Local time
Today, 19:59
Joined
Sep 6, 2004
Messages
894
Thats wonderful arnelgp

Thanks a lot. Only facing problem is. If I supply other language data such as Arabic to section name, it is storing ????? in the field. but with English it is perfectly working.
(y)(y)(y)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:29
Joined
May 7, 2009
Messages
19,169
consider using a Bound Dialog Pop-up form to add the Department and Section.
maybe it will save you Arabic text.
 

Ashfaque

Student
Local time
Today, 19:59
Joined
Sep 6, 2004
Messages
894
Yes you are correct. It is saving Arabic data thru bound form. But the form I am using is fully unbound. Is not there any possiblity with unbound form to store this data.
 

Users who are viewing this thread

Top Bottom