Check If Duplicate Afterupdate
Nov 30, 2006Hi, I was wondering if anyone knows the VB to check if a value is a duplicate afterupdate?
Many thanks.
Hi, I was wondering if anyone knows the VB to check if a value is a duplicate afterupdate?
Many thanks.
Someone fills in a new patient into the database, and the 'chipsoftnummer' which is the number in another database. That number is unique, so i want to have it where if someone fills in a number that already exists in the database the afterupdate event will open that record in the form.Here's the code i put in the input textbox update field:
private Sub chipsoftnummer_AfterUpdate()
Dim NewCHIP As Integer
Dim stLinkCriteria As Integer
Dim custNo As Integer
[code]...
It doesn't work, simple things like hello world do work so VBA is enabled.
I've attached the corresponding part of the database (took out all non-relevant fields and tabs) .
I have a form with a couple fields. i want to check to see if i have a duplictae field. the field is batch_ID. so if somoen tries to enter a batch_id thats already in the table a message box will popup saying duplicate record and it will take me to that record ?
Could i have an example please.
Hi folks,
I have this situation: a table with patients information and IDs, and a table with evaluations for those patients (identified by ID).
I am trying to make it so that the user can't add the same evaluation twice. I want to do it by checking if there is already an evaluation for that patient with the same date.
I know how to show evaluations only for a patient, but I don't know how to check if the value entered by the user in the date field is a duplicate (case in which he shouldn't be allowed to enter it). I assume this is done somehow through the "validation rule" property? But how should the expression be?
Thanks a lot!
dear all
i managed to get checking for duplicate record by ONE field ie member_no
code :
If DCount("*", "runner", "member_no = " & Me.member_no) > 1 Then
MsgBox " This member is already exist!" & vbCrLf
Me.c_memberid.SetFocus
Else
DoCmd.CancelEvent
End If
how i want to get checking duplicate record by TWO fields ie member_no and run_no ?
thanks in advance
I have a form - see attached image.
The first text box is called Job_No. When a number is entered here how can I check that the number doesn't already exist when the user tabs to the next box. Then if it does exist display a custom message to the effect "This already exists" and not the Access default duplicate error message.
Thanks
Michael
Hello All,
I have a database where a user imports data into a table monthly. She saves the Excel file and then clicks a button in Access to import the data. My instructions say to only click that button once, but so far, she has clicked it THREE TIMES, thus importing the data three times. How can I prevent this? Here is a copy of my import code:
Option Compare Database
Option Explicit
Public Function ImportTableData()
On Error GoTo ImportTableData_Err
Dim strPeriod1 As String
Dim strMM1 As String
Dim strYY1 As String
Dim strYYYY As String
Dim strFormName As String
Dim strMDPath As String
Dim strMDFileName As String
Dim strDCPath As String
Dim strDCFileName As String
'No Warnings
DoCmd.SetWarnings False
'Import Current Month data in a temporary table
DoCmd.OpenForm "frmEnterAgingDates", , , , acFormReadOnly, acHidden
strFormName = "Forms!frmEnterAgingDates"
strPeriod1 = Forms!frmEnterAgingDates.Period1.Value
strPeriod1 = Format(strPeriod1, "mmddyyyy")
strMM1 = Left(strPeriod1, 2)
strYY1 = Right(strPeriod1, 2)
strYYYY = Right(strPeriod1, 4)
strMDPath = "S:FinanceAccounting OperationsNational AccountsAccount Recs116405.100 and 117630.300116405.100-AR Due from PAR Plans NASCO"
strMDFileName = "MD AR Due from PAR Plans_" & strMM1 & strYY1 & ".xls"
strDCPath = "S:FinanceAccounting OperationsNational AccountsAccount Recs116405.100 and 117630.300117630.300-AR NASCO Refund Due from PAR Plans117630-2007"
strDCFileName = "DC AR Due from PAR Plans_" & strMM1 & strYY1 & ".xls"
DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "tblData_temp", strMDPath & strMDFileName, True
DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "tblData_temp", strDCPath & strDCFileName, True
'Append tblData_temp to tblData
DoCmd.OpenQuery "qryAppend_tblData_temp_to_tblData", acViewNormal, acEdit
'Delete any blank rows that may have resulted from the import
DoCmd.OpenQuery "qryDeleteBlankRows", acViewNormal, acEdit
'Delete the temporary table
DoCmd.OpenQuery "qryDelete_tblData_temp"
Beep
MsgBox "The file has been successfully imported", vbInformation, "Files Imported"
ImportTableData_Exit:
Exit Function
ImportTableData_Err:
MsgBox Error$
Resume ImportTableData_Exit
End Function
Thank you for your help!
I'm pretty new to Access, so please overlook any stupid questions :)
I have a data entry form that has one field that cannot be a duplicate. So, in the table I have it Indexed with No duplicates.
The problem is that the form doesn't notify the user that they have entered duplicate information until they close the form. So the 10 minutes they spent filling it out is wasted.
So, after consulting various posts, I did a BeforeUpdate event with the following code:
(the field that must be unique is called "LS Number", in the form "Q and D" based on the table "Q and D Database")
Private Sub LS_Number_BeforeUpdate(Cancel As Integer)
On Error GoTo LS_Number_BeforeUpdate_Err
If (DLookup("[LS Number]", "Q and D Database", "[LS Number]=Forms![Q and D]![LS Number]")) Then
MsgBox "The LS Number you entered already exists. Enter a unique LS Number", vbInformation, "Duplicate LS Number"
End If
LS_Number_BeforeUpdate_Exit:
Exit Sub
LS_Number_BeforeUpdate_Err:
MsgBox Error$
Resume LS_Number_BeforeUpdate_Exit
End Sub
When I test this by entering a duplicate LS Number, it gives me the error "Type Mismatch." Unfortunately, I have no idea what this means, nor do I know how to fix it.
Please help, my head hurts!
I have a problem where in a table called tblPatientLanguage
that contains three fields
PatientLanguageID
PatientID
LanguageID
a patient who is identified by PatientID can speak several languages
identified by the LanguageID.
The problem is with my current form and code
For Each varSelected In Me!lstLanguage.ItemsSelected
rs.AddNew
rs("PatientID") = [Forms]![frmPatientDemographics]![PatientID]
rs("LanguageID") = Me!lstLanguage.ItemData(varSelected)
rs.Update
Next varSelected
when the user click on the command button called cmdOK it will put the
data in the table "tblPatientLanguage" and corresponding fields. without
checking to see if there is already a duplicate languageID that corresponds to the
same patientID in the table
This has lead to duplicates in the table
example
PatientID = 9
if I look in the table I will see 7 entries that say
PatientID = 9 and LangaugeID = 7
I want to prevent this from happening with and if statement
I could make both the PatientID and LanguageID primary keys
this would prevent this from happening. But I would rather do it in
the VBA code? This way in will move thorugh the selections without poping an error and the person inputing the date. Any ideas sorry for being long winded. I attached the
database.
PS. If looking at the database you have to use form frmPatientDemographics and click on the language link
I have a simple database that I put my execptions in for the day for scanning. Is there a way that my serial field on my forum can check to see if someone already scanned that serial for that day using the "On Lost Focus" event.
View 7 Replies View RelatedI need to create a record of Users. I created a form with fields containing Username,FirstName,LastName & Email Address wherein the UserName is equals the value of the fields FirstName & LastName. I have a save command button and when I click it, I want it to be able to check if the new entry has a similar UserName that exists in the database, if it exists then it will allow me to edit the UserName and then save the data otherwise will allow me to save it.
View 3 Replies View RelatedHello
I have a three field table viz ItemName, ItemCode, ItemRate wherein ItemCode is Autonumber. What I needed was if I select 3 from dropdown of ItemCode, both ItemName & ItemRate be displayed on the form. A combo box can use to show one value and put other, but for twin values someone sugggested to use the AfterUpdate event. Is there no other way? I don't know how to code in Access. Can you please guide? Thanks
Is there a central reference on the net that explains the pro's and con's of each of the event types. I historically have used the OnChange event until the other day when someone suggested using the AfterUpdate instead.
Would like to ensure that I have the best event trigger being used where possible in various situations
Thanks in Advance
I Can't figure out why this doesn't work on a form that I want to populate the Timestamp field when they edit the record. Looks like it works for others that have posted.
Do I need to add a New Reference to the reference Libary?
I'm running Access2k
I get an error box stating the procedure declaration does not match description of event or procedure having the same name.
What am I missing?
Private Sub Form_AfterUpdate()
Me.Timestamp = Now()
End Sub
Bryan
I have a field on my form which I want to display a message box when something is entered.Private Sub BoI_AfterUpdate()Box = Msgbox("Is the booking date at least 7 days before the hiring and no more than 8 weeks in advance? If so, click Yes, otherwise, click No. You can check the calender on the Open Form under the 'Miscellanous' tab to check the date. Thank you.", vbYesNo, "Validation")If Box = vbYes Then Cancel = FalseElseCancel = TrueEnd IfEnd SubThat's my code, but I get an error after I type something in that field (BoI)."Compile error: Else without If" I have tried it with 'ElseIf Box = vbNo Then Cancel = True' but that also gives the same error.What's wrong with it?Thanks in advance. :D
View 4 Replies View RelatedI have a form with shipper information (5 fields) and a separate form/table of shippers. I want the ability to either enter shippers on the fly (one time shippers) or the option of picking a shipper from the shipper form/table and having it populate the 5 fields.
This is what I have and it works.
Private Sub FrgnShipCombo_AfterUpdate()
Me.FrgnShipName = Me.FrgnShipCombo.Column(1)
End Sub
Im looking for the how to use this method on multiple fields
Private Sub FrgnShipCombo_AfterUpdate()
Me.FrgnShipName = Me.FrgnShipCombo.Column(1)
Me.FrgnShipAddr1 = Me.FrgnShipCombo.Column(2)
Me.FrgnShipAddr2 = Me.FrgnShipCombo.Column(3)
Me.FrgnShipAddr3 = Me.FrgnShipCombo.Column(4)
Me.FrgnShipTeleNbr = Me.FrgnShipCombo.Column(5)
End Sub
I know what I want to do...but have no idea how to get started! I'm new to coding and using macros and quesries doesn't seem to help.
When field [TermDate] is updated with a value, I want to move the record from table [BadgeData] to table [Termed]. I'm sure this is easy for someone who'll be willing to throw out a few suggestions.
Also, is there anywhere in the code builder that will help identify what code (or commands) do? (Does that make sense?)
Hi. i am very thankful for all your help in my other queries for my database. i have one last question and i guess i will be done after that. i have a form which have 3 fields one is Number and the other is group and the next one is Account. all of them are combo boxes. I am trying to add this function in the Number field text box properties in afterupdate event which is as follow
Sub Number_Afterupdate()
If not isnull(Number) Then
Number=Format(Number, "000000")
Endif
End sub
The code is working fine. i debug it and run it no errors. i want to put this function in afterupdate. i copied this whole thing in the afterupdate box and when i go back to my control form try to enter numbers in the Number field it gives me this
Msaccess can't find the macro "private sub Mynumber" the macro or its macrogroup does not exist or the macro is new but has'nt been saved.
Can anyone help me out what i am doing wrong ? or can tell me steps what to do i really appreciate that and thanks alot FONZ :)
Hello all:
I have a split, shared database in which the Before and AfterUpdate events on my forms are not working at all. I tried setting a breakpoint to verify this and, sure enough, they are not firing.
Does anyone have any clue as to why this may be occurring?
Thanks so much for the help. I have tried searching the forum with no luck.
Hi
I'm having problems trying to get an If statement working on my form.
What I have is a form with two combo boxes linked to a Calendar when you click on the arrow. I can get the dates I select from the calendar into the combo boxes which works perfectly.
What I wanted to do then was create a textbox to list the number of days between each date.
I have created an If statement for me to do this, which works fine.
The problem I am having is that it doesn't seem to update these changes on the form after the date has been changed.
I have placed the code in the AfterUpdate event on both of the combo boxes and also in the Form Current Event.
Anyone any ideas?
If you want to see the If statement let me know, but I don't think it's that.
Thanks
Below is the code I have created to calculate the values "CalcValue" and "CalcWork". The values for AssignValue, AssignPriority, Complex, Effort, Goal are all assigned by the selection made in the referred to/related combo boxes. However, the caluclated values return the concatonation of the intergers and not the sum of the integers. Additionally, if I am to use the CDec() function how do I specify the number of decimal places?
what am I missing here?
thanks!
Private Sub cboAssignPriority_AfterUpdate()
Dim CalcValue, AssignValue, AssignPriority, Complex, Effort, Goal, CalcWork As Integer
Value = 0
AssignValue = 0
AssignPriority = 0
CalcValue = 0
CalcWork = 0
AssignValue = Me!cboAssignValue.Column(3)
AssignPriority = Me!cboAssignPriority.Column(2)
Complex = cboDBObjectID.Column(2)
Effort = cboTaskTypeID.Column(3)
Goal = cboAgencyGoalID.Column(2)
Value = AssignValue + AssignPriority
CalcWork = Complex + Effort + Goal
CalcValue = CDec(Value)
CalcValue = Me!lngCalPriority
Debug.Print "Complex="; cboDBObjectID.Column(2)
Debug.Print "Effort="; cboTaskTypeID.Column(3)
Debug.Print "Goal="; cboAgencyGoalID.Column(2)
Debug.Print "AssignValue.Column(3)="; cboAssignValue.Column(3)
Debug.Print "AssignPriority.Column(2)="; cboAssignPriority.Column(2)
Debug.Print "Value ="; Value
Debug.Print "CalcValue ="; CalcValue
Debug.Print "CalcWork ="; CalcWork
End Sub
I'm stumped....(newbie):)
I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and NotInList.
The AfterUpdate uses a 'me.recordsetclone' in order to display other data in controls associated with customerid/customername from the Customer table.
The NotInlist, does just that, adds a new customer name to the
list along with a new autonumber (used as customerid).
The problem is that I'm getting two entries (different autonumbers). I can't figure out what I'm doing wrong. If I remove the 'AfterUpdate' event, then I can't bring up the customer's data, since then there's no connection to the customername/customerid.
If I remove the Not in List, then there's no way to add a new customer. I reconfigured NotInList many many times and still I get 2 entries. One entry has Customer 'name only', The second entry has name, address, city and the rest of the fields as entered.
I tried setting an index (on Customer table) with CustID and CustomerID, making them unique, but still I'm getting 2 entries whenever I use the 'NotInList'..........Help Help,,
Here are these events:
Code: ( text )
Private Sub customername_AfterUpdate()
Dim rst As Object
Set rst = Me.RecordsetClone
rst.FindFirst "CustomerID=" & Me![customername]
If Not rst.NoMatch Then
Me.Bookmark = rst.Bookmark
Else
'Not found!
End If
Forms![Add or Delete Customer]![customername].Requery
End Sub
Code: ( text )
Private Sub customername_NotInList(NewData As String, Response As Integer)
Dim strSQL
Dim FirstName As String
Dim LastName As String
Dim SpacePosition As Integer
Dim lngNextID As Long
' Find the highest Cust ID in the Customers table and add 1
lngNextID = DMax("[CustID]", "Customers") + 1
custID = lngNextID
SpacePosition = InStr(NewData, " ")
If SpacePosition = 0 Then
MsgBox "Your entry requires a space to separate First and Last name." & _
vbNewLine & vbNewLine & _
"Please enter a First and Last Name or choose an entry from the list.", _
vbInformation, "Invalid Data !"
Response = acDataErrContinue
Exit Sub
End If
' Trim the data into first and last name using the space position.
FirstName = Trim(Left(NewData, SpacePosition - 1))
LastName = Trim(Mid(NewData, SpacePosition + 1))
If FirstName = "" Then
MsgBox "You have not entered details for the first name" & vbNewLine & vbNewLine & _
"Please fix entry.", vbInformation, "Invalid Data !"
Response = acDataErrContinue
Exit Sub
End If
If LastName = "" Then
MsgBox "You have not entered details for the last name" & vbNewLine & vbNewLine & _
"Please fix entry.", vbInformation, "Invalid Data !"
Response = acDataErrContinue
Exit Sub
End If
MsgBox "An account for this person does not exist....." & vbNewLine & vbNewLine & _
"Now creating new Customer Account.", vbInformation, "Unknown Customer Details....."
strSQL = "Insert Into Customers ([custID], [FirstName], [LastName]) " & _
"values ('" & custID & "','" & FirstName & "','" & LastName & "');"
'MsgBox strsql
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
End Sub
Is there anyone that can help....thanks Shasha
Hello,
I have an "After Update" event procedure for a field on a form that calls a VBA sub. When I use a different VBA sub to input a value in the above mentioned field, the "After Update" event does not occur, even thought the data in the field has been changed. (Of course if I manually enter the data, the field "After Update" event works.)
Is there a flag or condition that needs to be set in my VBA sub to let the field realize that it has been changed? Or possible a way to call the fields AfterUpdate Sub?
I tried having a my sub call the AfterUpdate sub to see what would happen, but didn't get it to work. I got a bunch of error and didn't feel like this was really the way to go.
I also could just duplicate all the code in the AfterUpdate sub for the field, but we all know that that is not a good idea.
Thank you for any help.
I have a form (TransactionBody) & a subform (Detail) in the body I have an option group (Reg Office, Unaccepted and Returned) and want the returned button to be true "IF" a box Yes/No box called "Returned" is checked "yes" in the "Detail" form.
I have done simular things in regular forms but not with a subform. I know I need to setup a afterupdate event in the Detail subform in the "returned" yes/no box and I know the basic if..then...else lingo I just don't know how to reference the transactionbody form in the formula from the detail form.
Any help would be greatly appreciated.
Thank you.
Hi all.
Benn looking through other posts and have found some things which look quite similar but nothing which answers the question simply enough for my standard!
Basically I have a form with 5 fields...Number, Name, Location, Date and Owner.
All fields are locked apart from Location and Date.
I have a combo box which lists the field "Number" and then displays the record's data. The aim of the form is to be able to update the Location field easily.
A user entering the form would use the combo box to select say number "3243". This would bring up record number 3243. The date displayed would be the last updated date. Currently 23/08/05. I am trying desperately to get the Date to refresh to the current date as soon as someone changes the "Location" field. I have tried putting in the AfterUpdate part of Location...Me.Date.Requery.
I feel that I may be well off track but that the answer I require is not too difficult. Please could someone advise?!?!
TIA.
--Update--
Think I've sorted it now everyone!!
My code looks like this, seems to do the trick.
Private Sub Combo15_AfterUpdate()
Me.Date = Format(Now(), "dd/mm/yy")
End Sub
I guess I should learn to try my hardest before posting here!! :)
Hi there,
I'd like to call a function when a bound textbox is updated and for some reasons it doesn't seem to work. It works when the textbox is unbound (or maybe I missed something)
Here is a very simplified version of the form:
http://img207.imageshack.us/img207/3618/apf4ax.jpg
MyFunction() is just a MsgBox for now and I'd like it to appear when the textbox in the main form is updated (i.e. when the text in the subform is updated). I set .AfterUpdate= "=MyFunction()" and .OnChange="=MyFunction()" but nothing happens.
(see attached code)
Thank you in advance !