G
gsnidow via AccessMonster.com
Greetings all. I need help making sure text entered in a certain field is in
the correct form. I am working with a batch number that is simply the date,
including hour and minutes, with no special characters. For example the
batch number for September 24 2007 10:30 am would be 0924071030.
The following is a double click event of a datasheet where the user double
clicks the "batch" field, and a popup opens with the batch from the datasheet
displayed in the patch field. I want to make sure that a valid batch number
is entered, but I do not know how to exclude letters, for example, or a
batch like 1301011200, where the '13' would not be a valid month. Any ideas?
I am using Access 2003 ADP with SQL Server 2000. Thank you.
Private Sub BATCH__DblClick(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rstblreel_notes As ADODB.Recordset
Dim strSQL As String
Dim strSQLI As String
Dim boolDupId As Boolean
'SQL to check if batch number already exists in the reel_notes table
strSQL = "Select batch FROM tblreel_notes where batch = '" & Me.
BATCH_.Value & "'"
'SQL to insert the record into the reel_notes table if it does not
already exist
strSQLI = "INSERT INTO tblreel_notes (reel_num,batch,reel_id) " & _
"VALUES ('" & Me.REEL.Value & "','" & Me.BATCH_.Value & "',
'" & Me.id.Value & "') "
boolDupId = False
Set rstblreel_notes = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rstblreel_notes.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
'============== Need Help here ===========================
'Right now I can only see if the batch is 10 digits long,
'but I would like to make sure it is valid in that it is a
'valid date and minute combination. Is this possible?
If Len("" & Me.BATCH_) <> 10 Then
MsgBox "Enter a valid batch#", vbOKCancel
Else
'============== the rest is good =========================
'Insert the record
If rstblreel_notes.EOF Then
boolDupId = False
DoCmd.RunSQL strSQLI
Else
'Open the form
If Not CurrentProject.AllForms("frmCable_Reel_Notes2").
IsLoaded Then
stDocName = "frmCable_Reel_Notes2"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
Forms!frmCable_Reel_Notes2.Requery
If CurrentProject.AllForms("frmCable_Reel_History").IsLoaded Then
Forms!frmCable_Reel_History.Requery
End If
End If
End Sub
the correct form. I am working with a batch number that is simply the date,
including hour and minutes, with no special characters. For example the
batch number for September 24 2007 10:30 am would be 0924071030.
The following is a double click event of a datasheet where the user double
clicks the "batch" field, and a popup opens with the batch from the datasheet
displayed in the patch field. I want to make sure that a valid batch number
is entered, but I do not know how to exclude letters, for example, or a
batch like 1301011200, where the '13' would not be a valid month. Any ideas?
I am using Access 2003 ADP with SQL Server 2000. Thank you.
Private Sub BATCH__DblClick(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rstblreel_notes As ADODB.Recordset
Dim strSQL As String
Dim strSQLI As String
Dim boolDupId As Boolean
'SQL to check if batch number already exists in the reel_notes table
strSQL = "Select batch FROM tblreel_notes where batch = '" & Me.
BATCH_.Value & "'"
'SQL to insert the record into the reel_notes table if it does not
already exist
strSQLI = "INSERT INTO tblreel_notes (reel_num,batch,reel_id) " & _
"VALUES ('" & Me.REEL.Value & "','" & Me.BATCH_.Value & "',
'" & Me.id.Value & "') "
boolDupId = False
Set rstblreel_notes = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rstblreel_notes.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
'============== Need Help here ===========================
'Right now I can only see if the batch is 10 digits long,
'but I would like to make sure it is valid in that it is a
'valid date and minute combination. Is this possible?
If Len("" & Me.BATCH_) <> 10 Then
MsgBox "Enter a valid batch#", vbOKCancel
Else
'============== the rest is good =========================
'Insert the record
If rstblreel_notes.EOF Then
boolDupId = False
DoCmd.RunSQL strSQLI
Else
'Open the form
If Not CurrentProject.AllForms("frmCable_Reel_Notes2").
IsLoaded Then
stDocName = "frmCable_Reel_Notes2"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
Forms!frmCable_Reel_Notes2.Requery
If CurrentProject.AllForms("frmCable_Reel_History").IsLoaded Then
Forms!frmCable_Reel_History.Requery
End If
End If
End Sub