need to write few error handling in my form. When user tries to enter jobcode if it does not exists in database should give me error. How do i write error handling in this form. My code is something like this.
Thanks
Ann
Private Sub cmdexit_click()
Unload Me
End Sub
Private Sub cmdReport_Click()
sqlReport
End Sub
Public Sub sqlReport()
Dim FromDate As String
Dim ToDate As String
Dim labCode As String
Dim prod As String
Dim sql As String
If Len(cboprod.Text) = 0 Then
Exit Sub
Else
prod = cboprod.Text
End If
' Debug.Print prod
If Not IsDate(txtfrom.Text) Then
'Exit Sub
Else
FromDate = CDate(txtfrom.Text)
FromDate = Format(FromDate, "mmddyyyy"
'Debug.Print FromDate
End If
If Not IsDate(txtto.Text) Then
' Exit Sub
Else
ToDate = CDate(txtto.Text)
ToDate = Format(ToDate, "mmddyyyy"
'Debug.Print ToDate
End If
sql = "select sum(e.totaltime)totaltime,count(e.empno)totalemp,e.line,e.labcode,l.description,e.jobnumber,(substring(PQ,1,10))as PQ,e.shiftnumber,e.date From emplhrdtltestlab e,labcode l Where jobnumber = '" & prod & "'and e.labcode=l.labcode and date between '" & FromDate & "' and '" & ToDate & "' group by e.shiftnumber,e.jobnumber,e.line,e.pq,e.labcode,e.date,l.description "
Dim rs As New ADODB.Recordset
rs.Open sql, cnn
Set LDRrpt = New LDR
LDRrpt.DiscardSavedData
LDRrpt.Database.SetDataSource rs, 3, 1
LDRrpt.ReadRecords
LDRrpt.ReportTitle = "DownTime Production Report for LAB "
LDRrpt.Text12.SetText prod
LDRrpt.Text8.SetText FromDate
LDRrpt.Text10.SetText ToDate
LDRVIEw.Show
End Sub
Private Sub Form_Load()
Me.Top = Labdowntime.Top
Me.RightToLeft = Labdowntime.RightToLeft
Set rs = New ADODB.Recordset
Dim sql As String
rs.Open "select distinct jobnumber from emplhrdtltestlab order by jobnumber", cnn, adOpenDynamic, adLockOptimistic
Do While Not rs.EOF
cboprod.AddItem rs(0)
rs.MoveNext
Loop
cboprod.Refresh
End Sub
Private Sub txtfrom_dblclick()
LDRCAL.Show
End Sub
Private Sub txtto_dblclick()
LDRCAL.Show
End Sub
Thanks
Ann
Private Sub cmdexit_click()
Unload Me
End Sub
Private Sub cmdReport_Click()
sqlReport
End Sub
Public Sub sqlReport()
Dim FromDate As String
Dim ToDate As String
Dim labCode As String
Dim prod As String
Dim sql As String
If Len(cboprod.Text) = 0 Then
Exit Sub
Else
prod = cboprod.Text
End If
' Debug.Print prod
If Not IsDate(txtfrom.Text) Then
'Exit Sub
Else
FromDate = CDate(txtfrom.Text)
FromDate = Format(FromDate, "mmddyyyy"
'Debug.Print FromDate
End If
If Not IsDate(txtto.Text) Then
' Exit Sub
Else
ToDate = CDate(txtto.Text)
ToDate = Format(ToDate, "mmddyyyy"
'Debug.Print ToDate
End If
sql = "select sum(e.totaltime)totaltime,count(e.empno)totalemp,e.line,e.labcode,l.description,e.jobnumber,(substring(PQ,1,10))as PQ,e.shiftnumber,e.date From emplhrdtltestlab e,labcode l Where jobnumber = '" & prod & "'and e.labcode=l.labcode and date between '" & FromDate & "' and '" & ToDate & "' group by e.shiftnumber,e.jobnumber,e.line,e.pq,e.labcode,e.date,l.description "
Dim rs As New ADODB.Recordset
rs.Open sql, cnn
Set LDRrpt = New LDR
LDRrpt.DiscardSavedData
LDRrpt.Database.SetDataSource rs, 3, 1
LDRrpt.ReadRecords
LDRrpt.ReportTitle = "DownTime Production Report for LAB "
LDRrpt.Text12.SetText prod
LDRrpt.Text8.SetText FromDate
LDRrpt.Text10.SetText ToDate
LDRVIEw.Show
End Sub
Private Sub Form_Load()
Me.Top = Labdowntime.Top
Me.RightToLeft = Labdowntime.RightToLeft
Set rs = New ADODB.Recordset
Dim sql As String
rs.Open "select distinct jobnumber from emplhrdtltestlab order by jobnumber", cnn, adOpenDynamic, adLockOptimistic
Do While Not rs.EOF
cboprod.AddItem rs(0)
rs.MoveNext
Loop
cboprod.Refresh
End Sub
Private Sub txtfrom_dblclick()
LDRCAL.Show
End Sub
Private Sub txtto_dblclick()
LDRCAL.Show
End Sub