
Originally Posted by
foxtet
Thank you for the reply,
that's right. if it works that pattern than that's fine..
user can select doctor's name from combo box so the text box should display the next token for the selected doctor..
fox
Okay,
Here is a code which issue tokens as per your request.
Code:
Private Sub Command4_Click()
'count the tokens...
Dim lngToken As Long
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
strSQL = "SELECT Count([tbltoken].tokenNumber) AS CountOfToken"
strSQL = strSQL + " FROM tbltoken"
strSQL = strSQL + " WHERE tbltoken.doctorid = " & Me.Combo0
strSQL = strSQL + " AND tbltoken.datetoken = " & Date
Set rs = db.OpenRecordset(strSQL)
lngToken = rs!CountOfToken
' lngToken = DCount("tokenNumber", "tbltoken", "doctorid =" & Me.Combo0 & " AND datetoken =" & Date) > 0
If lngToken > 0 Then
lngToken = lngToken + 1
Else: lngToken = 1
End If
Me.txtToken.Value = "Token No. " & lngToken
'record the token in the table with date
CurrentDb.Execute " INSERT INTO tbltoken " _
& "(tokenNumber, doctorid, datetoken) Values " _
& "('" & lngToken & "'," & "'" & Combo0 & "'," & Date & ")"
End Sub
two Tables involves:
tbldoctor (table)
with the following fields
ID (pirmery key)
doctorid
doctorname
tbltoken (table)
with the following fields
doctorid
tokenNumber
datetoken
==================
What this code does?
open the recordset and count the tokens for any doctor on the same dates.
'count the tokens...
Dim lngToken As Long
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
strSQL = "SELECT Count([tbltoken].tokenNumber) AS CountOfToken"
strSQL = strSQL + " FROM tbltoken"
strSQL = strSQL + " WHERE tbltoken.doctorid = " & Me.Combo0
strSQL = strSQL + " AND tbltoken.datetoken = " & Date
Set rs = db.OpenRecordset(strSQL)
lngToken = rs!CountOfToken
check for token if issued? and increment them:
If lngToken > 0 Then
lngToken = lngToken + 1
Else: lngToken = 1
End If
at last: record the issued token in the table
'record the token in the table with date
CurrentDb.Execute " INSERT INTO tbltoken " _
& "(tokenNumber, doctorid, datetoken) Values " _
& "('" & lngToken & "'," & "'" & Combo0 & "'," & Date & ")"
End Sub
Hope this meet your requirements:
the sample database can be attached if needed.