I have the following code wich is for entering new Project Nr's in an table, with the use of a combo box.
Now the code works fine, but I added the highlighted part. But it always gives me the message "This isn't a valid Project number.". And it should just add the number when something is typed in like "P017V001". The P is always there and followed by 3 numbers, then a character and aigain 3 numbers. and when it's not like this it should give the message.
An side question can I add something to convert the characters to capitals?
Code:
Private Sub Project_Text_NotInList(NewData As String, Response As Integer)
On Error GoTo Project_Text_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The Project number " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?", vbQuestion + vbYesNo, "Kenz")
If intAnswer = vbYes And [B][U]Me.Project_Text Like "P###?###"[/U][/B] Then
strSQL = "INSERT INTO tblProductSpecs([Project Nr]) " & "VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new Project number has been added to the list.", vbInformation, "Kenz"
Response = acDataErrAdded
Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Controls
ctl.Value = ctl.DefaultValue
Next
Set ctl = Nothing
Me.CraneEx_Text = Replace(Me.CraneEx_Text.DefaultValue, Chr(34), "")
Me.BoomEx_Text = Replace(Me.BoomEx_Text.DefaultValue, Chr(34), "")
Me.Project_Text = Replace(Me.Project_Text.DefaultValue, Chr(34), "")
AuxMacro
TuggerMacro
AMCMacro
AHCMacro
MOPSMacro
ManridingMacro
CTMacro
TelescopicMacro
ShockMacro
AntiMacro
DrivetypeMacro
ProductTypeMacro_False
SWLMacro_False
BridgeMacro_False
CompetitorsFieldMacro
FilterMacro
ScoreMacro
ElseIf intAnswer = vbYes And [B][U]Not Me.Project_Text Like "P###?###"[/U][/B] Then
MsgBox "This isn't a valid Project number.", vbInformation, "Kenz"
Response = acDataErrContinue
Else
MsgBox "Please choose a Project number from the list.", vbInformation, "Kenz"
Response = acDataErrContinue
End If
Project_Text_NotInList_Exit:
Exit Sub
Project_Text_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Project_Text_NotInList_Exit
End Sub
Now the code works fine, but I added the highlighted part. But it always gives me the message "This isn't a valid Project number.". And it should just add the number when something is typed in like "P017V001". The P is always there and followed by 3 numbers, then a character and aigain 3 numbers. and when it's not like this it should give the message.
An side question can I add something to convert the characters to capitals?