I have created a form that saves sales data into the database and if the user has not filled all fields, It should either display an error message or just highlight the empty textbox. In my case, I made the textbox be highlighted if empty but some of the textboxes such as the date and two of the combo boxes are not highlighted. If the textbox is not empty then save data which I already did code for saving data to the database. I just don't know how to structure to put the else statement that if the textbox isn't empty then save data. Screenshot: https://snipboard.io/t5keMo.jpg
This is my code:
Public Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim txt As Control
Dim combo As New Control
' While
For Each txt In Panel1.Controls
If TypeOf txt Is TextBox Then
If txt.Text = "" Then
txt.BackColor = Color.Yellow
txt.Focus()
End If
End If
Next
For Each combo In Panel1.Controls
If TypeOf combo Is ComboBox Then
If combo.Text = "" And combo.Text = "" Then
combo.BackColor = Color.Yellow
combo.Focus()
End If
End If
Next
For Each Dt In Panel1.Controls
If TypeOf Dt Is Date Then
If Dt.Text = "" Then
Dt.BackColor = Color.Yellow
Dt.Focus()
End If
End If
Next
' End While
End Sub
Save data:
Public Sub save_data()
' load_table()
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=root;database=golden_star"
Dim READER As MySqlDataReader
Try
MysqlConn.Open()
Dim Query As String
If (MessageBox.Show("Do you want to save the changes?", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then
Query = "insert into golden_star.sales (date,brand,size,selling_unit_price,cost_unit_price,quantity,cost_of_goods,profit,total_cost_price) values ('" & DateTimePicker.Text & "','" & ComboBox1.Text & "', '" & ComboBox2.Text & "', '" & txtSelling.Text & "', '" & txtCostPrice.Text & "', '" & ComboBox3.Text & "', '" & txtTotalSell.Text & "', '" & txtProfit.Text & "',
'" & txtCp.Text & "')"
Command = New MySqlCommand(Query, MysqlConn)
MessageBox.Show("Daily Sales Entered Successfully")
READER = Command.ExecuteReader
MysqlConn.Close()
End If
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
You should definitely be using the right control for the right data type. For example, do not use a TextBox for a DateTimePicker and use an ErrorProvider to indicate if a control has any errors.
Here is a very rudimentary example:
Private _errorProvider As New ErrorProvider()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' loop over every control in your Panel
For Each ctrl In Panel1.Controls.OfType(Of Control)()
' wire up the Validated event for the control
AddHandler ctrl.Validated, Sub(innerSender As Object, innerE As EventArgs)
' if the control does not have a value in it's Text property, then set an error
Dim validatedControl = DirectCast(innerSender, Control)
Dim validationError = If(String.IsNullOrWhiteSpace(validatedControl.Text), "Required", String.Empty)
_errorProvider.SetError(validatedControl, validationError)
End Sub
Next
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim anyErrors = False
' loop over the controls and select them to force validation
For Each ctrl In Panel1.Controls.OfType(Of Control)()
ctrl.Select()
If (Not String.IsNullOrWhiteSpace(_errorProvider.GetError(ctrl))) Then
anyErrors = True
End If
Next
' if any control has an error, then stop execution of the method
If (anyErrors) Then
Return
End If
' if there are not any validation errors, then continue with business logic
End Sub
Related
This question was asked in the topic with a similar name earlier, but the answer provided didn't really indicate HOW those events would help determine whether somebody was typing in the combo box or selecting an item in the list. I think that it really answered the other question about how to determine when somebody was done typing, but without seeing the event handlers, I can't be sure.
Unfortunately, I'm new here and don't have enough reputation to post a comment asking for clarification, so I have to start a new question. Here's what I'm trying to do:
I have a form with a combo box in the Header and, as I type in the combo box, I want the characters that I've typed to be used as a filter on the Details part of the form. Both the combo box control source and the form's record source use the same query string.
I've tried numerous iterations of the code below, but I can't get it to work correctly.
Private Sub cmbAppName_Change()
Dim strApp As String
Dim nSelStart As Integer
Dim nSelLen As Integer
Dim nSelected As Integer
Dim strMsg As String
On Error GoTo ERR_SUB
strMsg = ""
Me.cmbAppName.SetFocus
' Get current selection details
nSelStart = Me.cmbAppName.SelStart
nSelLen = Me.cmbAppName.SelLength
nSelected = Me.cmbAppName.ListIndex
Me.cmbAppName.SetFocus
strApp = Nz(Me.cmbAppName.Text, "")
Debug.Print "Index = " & nSelected & "; SelStart = " & nSelStart & "; SelLen = " & nSelLen
If nSelected = -1 Then
Debug.Print "Change by typing: " & strApp
Else
Debug.Print "Change by list selection: " & strApp
End If
' Get the part of the text that the user has typed
If nSelStart > 0 Then
strApp = Left(strApp, nSelStart)
Debug.Print "App piece = '" & strApp & "'"
End If
' If there is text, set a filter (MatchAppName = InStr(strApp, datbase_column_value)
If strApp <> "" Then
Me.Filter = "MatchAppName('" & strApp & "', " & DCApplications_Application_Col & ") > 0"
Me.FilterOn = True
' Me.txtApplication.SetFocus
' Call DoCmd.FindRecord(strApp, acStart, False, acSearchAll, False, acCurrent, True)
' Me.cmbAppName.SetFocus
Else
Me.Filter = ""
Me.FilterOn = False
End If
EXIT_SUB:
' Restore the selection in the combo box's text box
Me.cmbAppName.SetFocus
Me.cmbAppName.SelStart = nSelStart
Me.cmbAppName.SelLength = nSelLen
Exit Sub
ERR_SUB:
If ERR.Number = 2185 Then
strApp = Nz(Me.cmbAppName.Value, "")
Me.cmbAppName.SetFocus
Debug.Print "Using " & strApp
Resume Next
End If
Me.Filter = ""
Me.FilterOn = False
Debug.Print ErrorMessage(ERR.Description, "cmbAppName_Change", ERR.Number, "Value = '" & Me.cmbAppName.Value & "'", False)
Resume EXIT_SUB
End Sub ' cmbAppName_Change
As you can see from the error handling code, I'd often get an error 2185 telling me that my control didn't have focus when using the Text property despite having a SetFocus call right before it.
If somebody selects from the list (either by clicking or moving the selection), I'd like to go to that record, but I at least need the above piece working first.
After searching the Web, I found out that a Details section with zero records causes the 2185 error. Apparently, filtering like that causes problems when all records are filtered out.
The solutions on the Web said that you can set the Allow Additions property of the form to True, but that always displays one row in the Details section. This can be especially confusing if the rows in the Details section contain controls, which will be displayed in the "addition" row. Also, I would still get an error typing additional characters after the one that caused the Details section to have zero records.
Eventually, I replaced the combo box with a simple text control to filter the Details section. When the Details section has rows, I turn Allow Additions off and make the controls visible; when it doesn't have rows, I turn Allow Additions on and hide the controls.
Here's the code that I used:
Private Sub txtApplicationFilter_Change()
Dim strApp As String
Dim nSelStart As Integer
Dim nSelLen As Integer
Dim strFilter As String
Dim strQuery As String
Dim strWhere As String
Dim nRecs As Integer
On Error GoTo ERR_SUB
' Save text selection
nSelStart = Me.txtApplicationFilter.SelStart
nSelLen = Me.txtApplicationFilter.SelLength
' Get application name typed and selection information
strApp = Nz(Me.txtApplicationFilter.Text, "")
strFilter = "[" & DCApplications_Application_Col & "] LIKE '*" & EscapeQuotes(strApp) & "*'"
nRecs = DCount("[" & DCApplications_Application_Col & "]", LocalTableName(DCApplications_Tab), strFilter)
' Kludge code to prevent various errors (like 2185) when no records are returned in the form
Call UpdateList(nRecs)
' Update the record source to reflect the filtered list of apps
strWhere = " WHERE APPS." & strFilter
strQuery = strSelect & strFrom & strWhere & strOrderBy
Me.RecordSource = strQuery
' 20200423 SHM: Restore or update filter to avoid issues with Delete and Backspace and applications with spaces in their names
Me.txtApplicationFilter.SetFocus
Me.txtApplicationFilter = strApp
Me.txtApplicationFilter.SelStart = nSelStart
Me.txtApplicationFilter.SelLength = nSelLen
EXIT_SUB:
Me.btnAddNew.enabled = (Nz(Me.txtApplicationFilter, "") <> "")
Exit Sub
ERR_SUB:
' NOTE: ErrorMessage is a helper function that basically displays a form displaying the error
Call ErrorMessage(ERR.Description, "txtApplicationFilter_Change", ERR.Number, "Filter = " & strApp & " Records = " & nRecs)
Resume EXIT_SUB
Resume Next
End Sub ' txtApplicationFilter_Change
Private Sub UpdateList(nRecs As Integer)
Dim bShowControls As Boolean
On Error GoTo ERR_SUB
bShowControls = (nRecs > 0)
' Kludge code to turn off checkbox control source
If bShowControls Then
strSelect = strSelectStart & ", (" & strAppUser & ") AS " & strCtrlSource
Me.chkTestedByMe.ControlSource = strCtrlSource
Else
strSelect = strSelectStart
Me.chkTestedByMe.ControlSource = ""
End If
' Kludge code to prevent various errors (like 2185) when no records are returned in the form
' Turning on AllowAdditions prevents errors when no records are returned.
' However, that puts an empty row in the form, but the controls are showing, so we have to hide them to prevent confusing the user.
Me.AllowAdditions = Not bShowControls
Me.btnAddExisting.visible = bShowControls
Me.chkTestedByMe.visible = bShowControls
EXIT_SUB:
Exit Sub
ERR_SUB:
Call ErrorMessage(ERR.Description, "UpdateList", ERR.Number, " Records = " & nRecs)
Resume EXIT_SUB
Resume Next
End Sub ' UpdateList
I would use a work around to settle this issue
A simple code bellow demonstrate the work around using Tag property of Combo Box and keypress event along with change event, I hope it can be applied in your code
Private Sub Combo2_Change()
If Combo2.Tag = 1 Then
Text4 = "change - from key"
Else
Text4 = "change - from select"
End If
Combo2.Tag = 0
End Sub
Private Sub Combo2_KeyPress(KeyAscii As Integer)
Combo2.Tag = 1
End Sub
Don't forget to set Tag property of Combo Box to 0 on design view to avoid error at comparing empty Tag with number
I have an unbound textbox in form f_FeuilleBleue. In my code, I give it a certain value;
Debug.Print strAHNS '00 0AA 00-100 F TX-01
Form_f_FeuilleBleue.txt_AHNS = strAHNS
If I put a stopping point on the next line, the immediate window shows that
?Form_f_FeuilleBleue.txt_AHNS
answer: 00 0AA 00-100 F TX-01
However, I still see it as blank in my form. There is no data to be read!
How do I fix this? Is it an issue with screen updating? (I have nothing setting it to off) Maybe form updating? (I have a msgBox in the BeforeUpdate event but it doesn't go in that event)
EDIT - additional info:
When I open the form, there is no problem. I can change the value in the form or by code. However the issue only happens when the form is opened from a menu-style form. Code below. Even after the opening sub finishes, the textbox won't update (visually - it does in value). After testing I see that the Change and the Update event are NOT launched when changing the value of the textbox from another sub (Private subs may be the cause?) But why is it continuing to not show the values even after the subs end?
Could be very, very relevant to read but I'm not sure what to make of it: Obtaining textbox value in change event handler
Here is the code that opens the form:
Private Sub Command7_Click()
Dim strAHNS As String
Dim strquery As String
strAHNS = Replace(Mid(Me.Combo_Dessin2, InStr(Me.Combo_Dessin2, "=") + 1), "=", " ")
strquery = "[ID] = (SELECT Max([ID]) FROM [Feuilles])"
Debug.Print strquery
If (PremierAffichage) Then
DoCmd.OpenForm FormName:="f_feuillebleue", WhereCondition:=strquery
Else
MsgBox "Le projet ou dessin n'a pas été trouvé."
End If
End Sub
Function PremierAffichage() As Boolean
Dim rsFeuilles As DAO.Recordset
Dim rsProjets As DAO.Recordset
Dim strContrat As String
Dim strProjet As String
Dim strDessin As String
Dim sqlquery As String
Dim strAHNS As String
Dim strGroupe As String
Dim strMachine As String
If IsNull(Me.Combo_Dessin2) Or IsNull(Me.Combo_Projet) Or Me.Combo_Dessin2.Value = "" Then
PremierAffichage = False
Exit Function
End If
strProjet = Me.Combo_Projet
strAHNS = Me.Combo_Dessin2
strMachine = Mid(strAHNS, 4, 3)
strGroupe = Mid(strAHNS, 8, 2)
Debug.Print strProjet & " ** " & strAHNS & " ** " & strMachine & " ** " & strGroupe
sqlquery = "SELECT [AHNS], [Contrat], [No Projet], [EP (groupe)], [Type machine], [Mois] FROM [Feuilles]" 'WHERE [AHNS] = '" & strAHNS & "'"
Set rsFeuilles = CurrentDb.OpenRecordset(sqlquery)
sqlquery = "SELECT [Projet HNA] FROM [Projets] WHERE [Projet AHNS] = '" & strProjet & "'"
Set rsProjets = CurrentDb.OpenRecordset(sqlquery)
Debug.Print strAHNS '========================================--------
Form_f_FeuilleBleue.txt_AHNS = strAHNS ' this works in .value but not showing the result
DoEvents ' any changes from there on don't update the value visually
' ==========================================------
If rsProjets.RecordCount > 0 Then
rsFeuilles.AddNew
rsFeuilles![Contrat] = rsProjets![Projet HNA]
rsFeuilles![No Projet] = strProjet
rsFeuilles![AHNS] = strAHNS
rsFeuilles![Mois] = MonthName(Mid(Date, 6, 2))
If strMachine Like "[A-Z][A-Z][A-Z]" Then
rsFeuilles![Type machine] = strMachine
rsFeuilles![EP (groupe)] = strGroupe
End If
rsFeuilles.Update
PremierAffichage = True
End If
rsProjets.Close
Set rsProjets = Nothing
rsFeuilles.Close
Set rsFeuilles = Nothing
End Function
Assign your value to the active form instance (the open form) instead of to the form's class.
So assuming the open form's name is f_FeuilleBleue and you want to assign that value to the form's txt_AHNS control ...
'Form_f_FeuilleBleue.txt_AHNS = strAHNS
Forms!f_FeuilleBleue!txt_AHNS = strAHNS
Reference the form by its name as a member of the Forms collection.
I have an issue here .. i cant save combobox content into my table ... all other data are successfully saved but the combo box is saved either 1 or zero .. what seems to be wrong?
My tables are designed through navicat .. does this have anything to do with my choice of data type? knowing that I chose the data type to be Text
This is my code and it shows no run errors
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conStr As String = ("Data Source=localhost;user id=root;password=123456;database=sam;")
Try
Dim con As New MySqlConnection(conStr)
Dim cmd As MySqlCommand
For i = 0 To ComboBox4.Items.Count
con.Open()
Dim sqls As String = "INSERT INTO initial_nom(f_name,s_name,th_name,fo_name,app_no,adm_type) VALUES('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "'," & TextBox5.Text & ",'" & ComboBox4.SelectedIndex.ToString & "')"
cmd = New MySqlCommand(sqls, con)
cmd.ExecuteNonQuery()
Next
Catch ex As Exception
MsgBox("Error in saving to Database. Error is :" & ex.Message)
End Try
End Sub
SelectedIndex is integer which point to index of the selected item. Assuming that combobox's data source contains collection of string, try to use SelectedItem instead, type-cast it to string :
DirectCast(ComboBox4.SelectedItem, String)
I have developed a time monitoring system using fingerprint where the employee will scan his/her finger then it will record the time in and time out. But my problem is logging in and logging out by the employee is unlimited. Is there a solution where the employee can log in and log out ONCE IN A DAY? Every employee will log in and log out once. Here is my code for my Daily Time Record Form: (Im using visual studio 2010/Digital Persona UareU for my scanner)
Imports MySql.Data.MySqlClient
Imports System.Windows.Forms
Imports DPFP
Public Class frmDTR
Dim counter As Integer = 0
Dim oConn As New MySqlConnection(ConnectionString.ConnString)
Private matcher As DPFP.Verification.Verification
Private matchResult As DPFP.Verification.Verification.Result
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Me.Close()
End Sub
Public Sub SEARCH_EMPLOYEE()
Try
'Load From DB
GlobalFunctions.db_connect()
Dim reader As MySqlDataReader
Dim command As MySqlCommand = connection.CreateCommand()
command.CommandText = "SELECT * FROM employee_records WHERE ID_Number='" & strid & "'" 'check tag number if existing
reader = command.ExecuteReader()
If (reader.HasRows) Then
While (reader.Read())
With Me
'plot the data into controls
.txtID.Text = reader(1).ToString
.txtFirst.Text = reader(2).ToString
.txtMiddle.Text = reader(3).ToString
.txtLast.Text = reader(4).ToString
.txtAge.Text = reader(5).ToString
.txtBday.Text = reader(6).ToString
.txtDepartment.Text = reader(7).ToString
.txtYear.Text = reader(8).ToString
.txtGender.Text = reader(9).ToString
.txtContact.Text = reader(10).ToString
.txtMobile.Text = reader(11).ToString
.txtEmail.Text = reader(12).ToString
'fetch image from database
Dim imgBytes() As Byte = reader("image") 'image field
Dim image As Bitmap = New Bitmap(New System.IO.MemoryStream(imgBytes)) 'convert binary to image
.ProfilePic.Image = image 'show picture to picture box
End With
Call LOG_EMP() 'look up if login /log out
Timer1.Enabled = True
End While
Else
'Me.lblStatus.Text = "ID not recognized!"
End If
Catch ex As Exception
MessageBox.Show("Error scanning: " & ex.Message)
End Try
GlobalFunctions.connection.Close()
End Sub
Public Sub LOG_EMP()
Try
' Load From DB
GlobalFunctions.db_connect()
Dim reader As MySqlDataReader
Dim command As MySqlCommand = connection.CreateCommand()
command.CommandText = "SELECT * FROM employee_logs WHERE ID_Number='" & strid & "' AND Time_Out='Null'"
reader = command.ExecuteReader()
If (reader.HasRows) Then
While (reader.Read())
End While
'logout
Call EMP_LOGOUT()
Else
'log in
Call EMPT_LOGIN()
End If
Catch ex As Exception
MessageBox.Show("Error scanning: " & ex.Message)
End Try
GlobalFunctions.connection.Close()
End Sub
'insert login data
Public Sub EMPT_LOGIN()
' Connect to Database
GlobalFunctions.db_connect()
Dim command As MySqlCommand
Dim transaction As MySqlTransaction
transaction = GlobalFunctions.connection.BeginTransaction()
Try
command = New MySqlCommand("INSERT INTO employee_logs values('','" & txtID.Text & "','" & txtFirst.Text & "','" & txtMiddle.Text & "','" & txtLast.Text & "','" & txtDepartment.Text & "','" & Date.Today & "','" & TimeOfDay & "','Null') ", GlobalFunctions.connection, transaction)
command.ExecuteNonQuery()
transaction.Commit()
'sms = txtFirst.Text & " Enter the Building Premises #" & Now 'actual sms
lblStatus.ForeColor = Color.Lime
Dim SAPI
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Welcome!" & txtFirst.Text)
Me.lblStatus.Text = "Successfully Logged IN! Welcome!" 'set status to login
'Will_SendSMS() 'send sms to number
Catch ex As MySqlException
MessageBox.Show("Error in inserting new record! Error: " & ex.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
transaction.Rollback()
End Try
'close connections
GlobalFunctions.connection.Close()
End Sub
Public Sub EMP_LOGOUT()
' Connect to Database
GlobalFunctions.db_connect()
' Dim command As MySqlCommand
Dim transaction As MySqlTransaction
transaction = GlobalFunctions.connection.BeginTransaction()
Try
GlobalFunctions.execute_nonquery("Update employee_logs set Time_Out='" & TimeOfDay & "' WHERE ID_Number='" & strid & "' AND Time_Out='Null' AND Date='" & Date.Today & "'")
transaction.Commit()
'sms = txtFirst.Text & " Left the Building Premises #" & Now & "Powered by: " ' actual sms to be sent
lblStatus.ForeColor = Color.Lime
Dim SAPI
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Goodbye!" & txtFirst.Text)
lblStatus.Text = "Successfully Logged OUT! Goodbye!" ' set status to logout
'Will_SendSMS() 'send sms
Catch ex As MySqlException
MessageBox.Show("Error in updating a record! Error: " & ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
transaction.Rollback()
End Try
' close connections
GlobalFunctions.connection.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'counter for display
counter += 1
If counter = 6 Then
Call ClearTextBox(Me)
lblStatus.ForeColor = Color.Lime
Me.lblStatus.Text = "Please scan your finger....."
Lblverify.ForeColor = Color.Black
Lblverify.Text = "Status"
ProfilePic.Image = Nothing
Timer1.Enabled = False
counter = 0
End If
End Sub
Private Sub frmDTR_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Try
Me.VerificationControl.Focus()
Catch ex As MySqlException
MessageBox.Show("System Error: " & ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub frmDTR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
matcher = New Verification.Verification()
matchResult = New Verification.Verification.Result
Me.VerificationControl.Focus()
Dim SAPI
SAPI = CreateObject("SAPI.spvoice")
SAPI.Speak("Please scan your finger")
End Sub
Private Sub VerificationControl_OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles VerificationControl.OnComplete
Dim strSQL As String = "Select * from finger_template"
Dim oDa As New MySqlDataAdapter(strSQL, oConn)
Dim dt As New DataTable
Dim dr As DataRow
Try
oDa.Fill(dt)
For Each dr In dt.Rows
Lblverify.ForeColor = Color.Red
Lblverify.Visible = True
Dim bytes As Byte() = Nothing
bytes = dr.Item("byte_template")
Dim tmplate = New DPFP.Template()
tmplate.DeSerialize(bytes)
matcher.Verify(FeatureSet, tmplate, matchResult)
If matchResult.Verified Then
EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
strid = dr.Item("Account_ID")
Call SEARCH_EMPLOYEE()
Exit For ' success
End If
If Not matchResult.Verified Then EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
Lblverify.Text = "Status"
lblStatus.Text = "Unrecognize fingerprint....."
Lblverify.ForeColor = Color.Red
lblStatus.ForeColor = Color.Red
Timer1.Start()
Next
Catch ex As Exception
End Try
End Sub
End Class
This is very nice that you are developing this logic. Actually I have come a crossed YOUR question. Now I can recommend you some vb.net code using back end MS ACCESS 2007 .well You just validate when an employee logged in then put this code after log In button or what ever you are using .
Dim cmd1 as oledbcommond
cmd1 = New OleDbCommand("SELECT * FROM LOGTIME WHERE timein<>null and timeout<>null and dt='" & Label8.Text & "' and eid='" & txtemid.Text & "' ", cn)
dr = cmd1.ExecuteReader()
If dr.Read Then
MessageBox.Show("Already this Employee ID contains today's attendance,now you can't Log again", "Information On Your ID", MessageBoxButtons.OK, MessageBoxIcon.Information)
cmd1.Dispose()
cn.Close()
Exit Sub
End If
just follow the steps
Use normal login button which will validate for user
then if the authenticate user then show his login time in another textbox in the same form.and
use one more textbox to show the logout time ,now
1)use two buttons a)button1 as logintime button and b)button2 as logout time button
2)Then write code to add the login time into the data base,and for ur better understanding put one message box too which will shows the"Time in added to the database" and after that put the above code which will validate the current day attendance if the employee wants to login twice or thrice in a day this code will not allow him to login again only once he/she can ... and code the above behind the login button
note:-keep in mind that all the procedure will work after the employee log out ..Hope this will help you out..
I'm having problems with the execution of ServerFilterByForm in Access 2003
When I apply the entered filter it returns the requested data but after it appear on screen (Form) it disappears. Don't know why this is happening
Does anyone had the same problem? How can it be solved?
Here is part of the code"
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
Dim stSql As String
If Len(ServerFilter) > 0 Then
stSql = "SELECT * FROM v_InitialReviewQuery " & _
" WHERE " + ServerFilter & _
" ORDER BY acctnumber"
Else
stSql = "SELECT top 1 * FROM v_InitialReviewQuery ORDER BY acctnumber"
End If
Me.RecordSource = stSql
End Sub
Try changeing this line
" WHERE " + ServerFilter & _
To
" WHERE " & ServerFilter & _
Also what is the value of ServerFilter?
I have a similar .adp.
The method I use to set the queue is a view on a form (I use it as a subform that has various process queues) that provides the critera for the serverfilter. This would replace your "select top 1 *" and me.recordsource. The form is imbedded as a sub form on a main form that I provide information about various queues. Number in line, next to be worked, next SLA expiration... I use this to open the initial form:
Dim stDocName As String
Dim stLinkCriteria As String
Dim Next_TD_ID As String
Forms![Launch_Control]![queue_subfrom].Form.Refresh
Next_ID = Forms![Launch_Control]![queue_subfrom].Form.[nxt_id]
stLinkCriteria = "nxt_ID = " & Next_ID
stDocName = "Work_form"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Then on the work_form I use 2 buttons
One for the next work_item in the que:
private sub next_button_click()
dim nxt_id as string
nxt_id = Forms![Launch_Control]![queue_subfrom].Form![nxt_id]
Me.ServerFilter = "identifier_in_view = " & Nxt_id
Me.Refresh
end sub
The other to call the filterby from command.
Private Sub button_click(button As String)
Forms![your_form].Reviewer.SetFocus
Me.ServerFilter = ""
Me.Refresh
Me.ServerFilterByForm = True
Me.Refresh
DoCmd.RunCommand acCmdServerFilterByForm
end Sub
FYI my subform refrence may not be exacly correct.
Hope this helps.