Forms :: Dmax Count By User
Jun 28, 2014
My code is supposed to advance the number of times the current user who is logging in and advance by one. It is NOT doing this by the Current User? It is advancing the count from the greatest number by one?
Need to modify SQL to allow for txtlogincnt ? ? ?
txtUserID is the Users Login Name.
LoginCnt is the number of times the User has Logged in.
1 Other pieces of code that get's the Log Count per User logging in. This part works!
'Get Login Count.
Quote:
Me.txtlogincnt = DLookup("[LoginCnt]", "tblUserSecurity_Sec", "[userID]='" & Me.txtUserID.Value & "'")
Quote:
'Update Login Count
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblUserSecurity_Sec SET tblUserSecurity_Sec.LoginCnt = '" & Nz(DMax("LoginCnt", "tblUserSecurity_Sec") + 1) & "' " & _
"WHERE (((tblUserSecurity_Sec.userID)='" & Me.txtUserID.Value & "'));"
DoCmd.SetWarnings True
View Replies
ADVERTISEMENT
May 9, 2013
DMax multi user.I don't get a PO number and when I click on my subform I can't change the values because it says I need to add multi user.Also code that Chris O and RainLover had references additional fields which I don't have. I only have the one field that needs updating.I have PONumber textbox and tbl.Purchase with the field PO..Here's the code I used.
Private Sub PONumber_AfterUpdate()
If (conHandleErrors) Then On Error GoTo ErrorHandler
' If we have some data
If Len(Me!PONumber) Then
[code]....
View 5 Replies
View Related
Oct 11, 2013
I'm using the following code to generate a sequential number"
Code:
Private Sub Form_Load()
Me.txtReceivedDate = Now()
'assign an EmailID when form loads
Dim CurMax As Long
Dim NewMax As Long
'poll the current EmailIDs for the largest number from current year and add 1
[Code] ....
Until recently, I didn't have any criteria on the DMax and it worked perfectly. It's now been decided that the EmailID should reset back to 1 when the calendar year changes.*
*EmailID is not my primary key - There is a separate autonumber field used as the primary key.
The table I'm using the DMax on has a field named ReceivedDate which stores a Now() when a record is created. The form I'm working in has a textbox named txtReceivedDate that is set to Now() when the form loads as can be seen in the code above.
What I'm trying to use as my criteria in the DMax is to match the Year() of ReceivedDate in tblEmails to the Year() of txtReceivedDate on the form.
For 2013, the current max (CurMax) EmailID is 21. If I set my computers date back to 2012 (where the CurMax is 3) the txtEmailID is still being populated with 22, even though txtReceivedDate shows a 2012 date.
I've tried a handful of permutations of the criteria string:
Code:
Year([ReceivedDate]) & " = " & Year(Forms!frmNewEmail!txtReceivedDate)
Year([ReceivedDate]) & "=" & Year(Forms!frmNewEmail!txtReceivedDate)
Year([ReceivedDate]) = Year(Forms!frmNewEmail!txtReceivedDate)
I've tried a few others long the way that I don't even remember, but there's probably little value in listing all the ways that don't work.
I've got a syntax issue within the criteria since it's the first time I've tried to use one and it contains a couple moving parts.
Once I get this sorted out a follow on question is about dealing with the users changing the txtReceivedDate to a different year. As of now, I have the same code (everything except "Me.txtReceivedDate = Now()") also present in txtReceivedDate_LostFocus(), but I'm not sure that's the best place for it.
View 5 Replies
View Related
May 22, 2013
I am currently creating a form to input new return parts into a database. I am trying to automatically generate a tracking number (##-AA-####-####). I have gotten myself to generate the ##-AA-#### in a list box and almost was able to generate the sequence number, 0001, 0002, etc. using the dmax function. I would like to generate the sequence number one higher than the highest, depending on part type and last 4 digits of part number. Our parts have unique last 4 different p/n but more than one can fall under the same type.
View 14 Replies
View Related
Nov 30, 2007
I may be making this more difficult than I need to, but here is the situation. I am trying to create a query that counts total records that fit a specific criteria, but I would also like it to display a 0 if there is no criteria to count. The following is an example of one of these queries:
SELECT Count(*) AS [Total DialsAnsweringMachine], dbo_AODCallDetail.Service_Id
FROM dbo_AODCallDetail
WHERE (((Year([CallStartDt])*12+DatePart("m",[CallStartDt]))=Year(Date())*12+DatePart("m",Date())-1) AND ((dbo_AODCallDetail.SwitchDispId) In (3)))
GROUP BY dbo_AODCallDetail.Service_Id;
As you can see, I am grouping by dbo_AODCallDetail.Service_Id, but when I run the query it only shows be the IDs that have results based on the criteria. I want it to show me all of the counts, even if the count = 0.
Thank you for the help.
View 3 Replies
View Related
Sep 3, 2014
I am using several queries with Region Codes coded in the query. My reports are also based on the individual queries and has a Record count statement as well --
=DCount("[State]","Reporting Query1"). All is working fine.
Now to minimize the number of queries I need to write, I want to prompt for the Region code. I can do that [Enter Region Code:]. It prompts and the report shows the expected output (only records for that region code) BUT my count statement ceases to work and I get #Error instead of the number of records. This happens no matter which field I set to prompt.
View 9 Replies
View Related
May 22, 2013
I am building a form in access and I am trying to find a way where user input isn't possible in the associated textbox when "No" from on option box is selected.
View 3 Replies
View Related
May 23, 2013
I have made a basic form and use it a log on screen. This requires the user to in put a user name and a password before gaining access to the main database.
The background to the form is a table where the users details are entered including the i enter the user name and password.
Is there any way to add a counter that is only visible in the table, so I can report on the different users.
View 14 Replies
View Related
Sep 15, 2006
Thanks for all the help to date.
Problem trying to get a dmax field for an invoice no in a query - am doing something wrong current attempt below won't work
Expr1 :dmax([Invoice no],[Table name]![Invoice no])
what am I missing - do I need something on the end when I get this to work I will use it to add 1 for the final query prior to print
View 4 Replies
View Related
Dec 21, 2006
Okay...I know the basic syntax for Dmax (or at least I thought I did) but I cannot get this statement to do what I want!
In the <before update> event I tyoed this:
Dim RNum As Long
Me.txtRNumber = DMax("[Request_Num]", "test_request") + 1
Me.txtRnumber = RNum
txtRNumber is the field on the form
Request_Num is the field on the table
test_request is the table
yes...I know the name syntax is bad (it's an older db I'm using as a test for a newer one).
Obviously, I want to automatically increment the field value by 1 on every new record (an if newrecord clause is included). But I just can't get the stinkin thing to work!!!
View 12 Replies
View Related
Oct 3, 2006
I am having difficulty understanding under which circumstances I should be using Max() as opposed to DMax() functions. Both seem to do the same thing (find maximum value in a field), but DMax has additional arguments.
What I currently want sounds like neither of these, as I want to query the maximum of several values in various fields for a specific record, rather than the maximum of several records in a specific field. Is there a way of doing this otherwise than by nesting IIF functions several deep?
I keep running into "Microsoft Office Access has encountered an error and needs to close" error messages, and am coming around to the view that I may need a UDF. I have never done one in Access before (but did some time ago in Excel).
Currently I have fields in various tables:
T_Clients.Commencement
T_Clients.Cessation
T_Tasks.StartDate
T_Tasks.EndDate
There is a one (T_Clients.ID_Clients) to many (T_Tasks.ID_Clients) relationship
T_Clients.ID_Clients and T_Tasks_ID_Tasks are primay keys.
In "pseudocode" my query, probably via a UDF, needs to return:
Min(Max(StartDate,Commencement)+12months,Min(EndDa te, Max(Cessation,StartDate))+9months
Commencement and Cessation may contain Null values, which are then to be treated as #1900-01-01# for the purposes of any comparisons.
My first attempt at this was to create several queries, each based on the previous query. Inefficient, perhaps, but I could trace the logic. I started by creating queries that substituted #1900-01-01# for null values in the Commencement and Cessation fields.
However when I got about 3 queries deep I ran into the "Access has encountered an error and needs to close" error, and no amount of playing around with it stopped that.
I don't know if relevant but I don't *really* have a T_Tasks.StartDate field. I have a query that calculates the start date from the previous EndDate, but I did not want to complicate the problem specs. That query seems to work ok. If I get a solution to the above I hope to jigger it to fit.
View 3 Replies
View Related
Jul 1, 2006
I've searched the forum and can't quite find what I need so I'm asking for further guidance form all you Access masters out there!
I have a field 'Time' in the format of 'dd/mm/yyyy hh:mm' which has a default value of =DMax("Time ","[Monitoring]")+1.
This increments 1 on the 'dd' bit when each new record is created, however what I want is for the hour (hh) bit to increment 1 on each new record.
Not sure if I'm being niave but I thought it was some sort of formatting issue, so I've dabbled with a few but to little effect unfortunately.
View 6 Replies
View Related
Oct 13, 2004
I want to create fields that are in the form IC0000001, IC0000002, etc. I can do the increment in the numbers by using the dmax function but how do I add the alphabets before it? How can I start with 0000001 instead of 1? Any help would be greatly appreciated, thanks so much!
Swee
View 3 Replies
View Related
Jan 18, 2006
Hello,
I am using DMax() to return the highest date in a table, but really need it to return the second-highest...so, if I had:
14th Feb
10th Dec
1st Jan
I don't want it to return 10th Dec, I want it to return 14th Feb
Any help much appreciated. I am sure there was something like dmax()-1, but that just returns (in my example above) 9th Dec!
Thanks!
View 4 Replies
View Related
Dec 4, 2006
Hello peeps!
Just someone advice if I can!
I have a table that contains student details:
StudentNo
Surname
Forename
I have created a form to add students to this table but I need a button that will read the highest StudentNo and then add one, putting the new stundent number in the form in a new record?
How can I go about doing this? Can it be done using a macro or do I need to use VBA??? I have been told that I would need to use the DMax function but I dont know VBA.
Thanks in advance for all your help
View 4 Replies
View Related
Mar 24, 2008
Hi
I have a table with three key fields
table name is tblSampleDetails
Field names are
ClientSampleRef
BatchNumber
Visual
A Batch may have many samples of which some may be visuals
Currently I store a variety of values (some number, some text and some a combination of both) in ClientSampleRef but I would like to start on some samples creating the value for the ClientSampleRef
If the sample is a visual (this is indicated by a check box on the form giving a value of -1) I would like to make the ClientSampleRef = Visual 1 this would then increment within the same batch by one each time.
I have taken some code from Dev Ashish and Arvin Meyer and changed the field and table names but I am getting an error saying there is a missing operator
If Check42 = -1 Then
Me.ClientsSampleRef = "REC-" & Right(DMax("ClientSampleRef", "tblSampleDetails"), Len(DMax("ClientSampleRef", "tblSampleDetails")) - InStr(1, DMax("ClientSampleRef", "tblSampleDetails"), "-")) + 1
End If
I am just testing this code so I have created a record with a value of REC-1 in the field ClientSampleref
I have also created a test database and the code works within that upto a value of REC-10 then I get problems
any help or pointers greatly appreciated
Richard
View 1 Replies
View Related
Jul 13, 2005
HI All,
I'm using
Between DMax("DateFieldName","TableName")-10 And DMax("DateFieldName","TableName") expression
in query to find time interval 10 days prior the last record puting this into Date field in my query Criteria. It's working fine.
But I want to find time interval a Month and an Year prior the last record.
I'm thinking to use DateDiff func to calculate properly intervals.
Between DMax("DateFieladName","TableName")-DateDiff ("m",1-2-100,1-1-100) And DMax("DateFieldName","TableName") --> for a month
That function also work but I'm not sure if it calculate correct result
Any better ideas? Thanks!
:cool:
View 3 Replies
View Related
Jul 23, 2005
Hello Access friends,
Trying to have a sequential autonumber for the ScreenID with the DMax () function.
Please advise on what is wrong with the following :
=Nz(DMax("[ScreenID]","[Screenprep]","[ScreenID] = '" & [CarModel] & "-" & Left$([Category],1) & "'")+1,0)
Neither putting this code in control source or beforeupdate event of the form is not working.
I have looked around and from previous posts in the forum come up with this module. But it is not working either:
Public Function NewScreenID() As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim ScreenID As String
Dim CarModel As String
Dim Category As String
On Error GoTo Err_Execute
Set db = CurrentDb()
Set rst = CurrentDb.OpenRecordset("SELECT Max([Screenprep].[ScreenID]) AS MaxScreenID from [Screenprep];", dbOpenSnapshot)
If IsNull(rst!MaxScreenID) Then
NewScreenID = [CarModel] & "-" & Left$([Category], 1) & Format(1, "0000")
Else
NewScreenID = rst!MaxScreenID + 1
End If
rst.Close
Set rst = Nothing
Set db = Nothing
NewScreenID = ScreenID
Exit Function
Err_Execute:
'An error occurred, return blank string
NewScreenID = ""
MsgBox "An error occurred while trying to determine the next sequential number to assign."
End Function
In advance thank you for your time.Can someone please guide me on how to sort this out?
View 1 Replies
View Related
Jun 4, 2006
Hello gentlemen,
My main form contains a Entry_No (Text – Not duplicate) field. I used following code in the same form in a command button’s OnClick event to increment integer value of Entry_No to “Issue-1”, Issue-2”, “Issue-3” & so on.
Dim strmax As String
strmax = DMax("[Entry_No]", "T_Drug_Receiv_Head")
Me!Entry_No = "Issue-" & Right(strmax, _
Len(strmax) - _
InStr(1, strmax, "-")) + 1
No problem with above code. It works fine.
The record source of the main form initially was based on query which I removed later. I placed following code to display only the last record while form opens (on Open event). This is a try due to very large table and I don’t want my form / query to load all 90,000 records into the memory at one time that takes time.
I placed a unbound text box (TxtMaxt) to disiplay Entry_No field of last record of the table which is ok.
Txtmax = DMax("[Entry_No]", "T_Drug_Receiv_Head") ‘ This is OK.
Dim NSSQL As String
NSSQL = "Select * from T_Drug_Receiv_Head where [Entry_No] = Txtmax"
Me.Form.RecordSource = NSSQL
Me.Refresh
When I open the form, it asks me ‘Enter parameter value’ for ‘Issue’. When enter something then dialog closes and form appears with blank record except showing displaying Entry_No field of last record of the table in the Txtmax unbound text box.
When I removes code from on open event and selects query that was set before as record set, it works.
Where might have gone wrong?
With kind regards,
Ashfaque
View 12 Replies
View Related
Jul 24, 2013
I just wondering if there is any way to Dmax more than one field? I found something and tried it but it does not seem to work.
Text13 = 10
Text15 = 5
I expected to get a result of just 10 but didn't
Code:
Dim Junk As Variant
Junk = DMax("[Text13] & ', ' & [Text15]", "Test")
MsgBox Junk
View 5 Replies
View Related
Dec 22, 2012
I have a form with a combobox where I select the Carrier witch then populates a multiselect listbox with all the record from that carrier in the specified date. When I select them and click save I want all the record ID(ConID) saved under the same ID(manifest ID) ie,
1 223
1 225
2 344
2 4444
Ect
It saves it in a table called Manifest With the fields Manifest ID and CONID which is a lookup field to a different table. Here is my current code for the on click command
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Manifest", dbOpenDynaset)
[Code] ....
Now I've done some searching and I thin dmax is what I want to use.. But I am not sure how to make it work...
View 4 Replies
View Related
Mar 7, 2005
I'm reading lots of threads about various problems with autonumber, and I encountered a corruption in a very beginning database myself, using the autonumbered field as a sequential file number, my primary key. So, my question is.....how is the very most simple, NOVICE, way to use DMax (step by step on what to write and where to put it) to create a sequential file number, starting from 00001 and ad infinitum until I go out of business :)
I simply want a field called "file number" that will effectively auto-number, without the dangers of autonumbering crashes etc.
Thanks for your suggestions!
View 3 Replies
View Related
Jun 27, 2007
I have data in a table
I am extracting using an append Query, I wish to assign a number from the original table +1 to the records pulled by the append query.
I am very new to this and have the expression below, however the result is #error in created field CertifNumber
The data I am looking for is in table Sample Details and the Field is CertNo
CertifNumber: DMax([Sample Details]![CertNo],"Sample Details","[Sample Details]![CertNo]+1")
If somebody could help me with this expression I would be very grateful.
Thanks
Richard
View 3 Replies
View Related
May 14, 2006
Hello,
I have inherited a database that already has heaps of records in it. One of the forms which is used constantly, has a "BookNumber field" (taken from an underlying table called "Participants". At the moment, this number is entered by hand, but it really could be done automatically increasing by 1 each time a new record is created.
My questions are these:
1. If the BookNumber field in the Participants table is a text field, can I use DMax on it, or does it need to be a number field?
2. If it does need to be a number field, will it cause problems to the existing records if I change the text field to a number field in the table design?
3. Where do I put the DMax statement - in the table or in the form? I am assuming that I put it in the form, but point it to the table is that right?
I know you have answered heaps of questions about DMax before (I think I have read just about every one), but I'm still having trouble figuring this out. I tried putting a text box in the form that had an expression that read: =DMax("BookNumber", "Participants")+1 as it's data, but it just came back with an error message.
Please help...
Thanks,
QuietAchiever
View 3 Replies
View Related
Aug 8, 2013
after I insert a new record using INSERT INTO and then use DMax() (in a private sub) to look up the new record. About half the time DMax() pulls the new record based on the primary key field (AutoNumber) just fine. However, half the time it pulls the max record prior to the new record being inserted. I.e. record 1001 was added and DMax() pulls record 1000. I'm assuming that my issue has something to do with the timing of when the record is writen/saved in the table. Is there a simple method of refreshing the table that I can use prior to using DMax()?
View 2 Replies
View Related
Apr 15, 2015
How do i use DMax() function instead of Autonumber, since the table is empty and it wont know what to do with Dmax() + 1 for next record?
E.g I have a new table Customer_details which contains
customerID
customerName
Age
now if i enter data through forms, i want the CustomerID to be incremental for each new record, so i can use Dmax() function. But since the table is empty how can i tell the form, through VBA that if it is null store 1 else store Dmax("CustomerID", "Customer_Details") + 1
View 2 Replies
View Related