I've a form in which one of the fields the user enters is supposed to be a unique id. The unique id is an alphanumeric text box.
However, it's possible that another user enters an id that has already been previously used.
I'm thinking that I need to run a Find Duplicates Query with the text box entry and a table that holds all the previously entered ids prior to the form being saved so that I can inform the user of the possible duplication.
My question is are there any ideas on how I can do this or code it?
I have the following in the after update event in a Combo bound to a tbl on a Main form; Sub Combo8_AfterUpdate() ' Find the record that matches the control. Me.RecordsetClone.FindFirst "[Vendor] = '" & Me![Combo8] & "'" Me.Bookmark = Me.RecordsetClone.Bookmark End Sub
The Combo gets its data from a table and I use the Not In List to add data which is not in the Tbl and of course Limit To List is set to Yes. It works ok with one exception, when data is entered, but not saved, then deleted And the form closed. In this set of circumstances I get an error in the code above. Granted that normally a user will not delete data from the combo then exit the form but it does happen occasionally. I have tried adding On error goto.... but with no luck. Any suggestions?
So on the offchance that two clients are trying to autogenerate a key at exactly the same time, I'm trying to trap the 3022 error raised when a duplicate key is entered so that I can repeat the operation with a goto.
I'm raising the error with requery like this:
DoCmd.Save acForm, Me.Name 'next line triggers 3022 DoCmd.Requery
After I realised that the normal handler wouldn't trap it I got the database from this thread:
I have a VBA code that runs an append query to update a table. Due to relationship integrity a validation error shows (a type does not exist in the connected table): What I want to do is trap the error and write something that the user can understand. Help !
The Code: Code:Private Sub Report_Deactivate()Dim Msg, Style, Title, Response, MyStringMsg = "Click OK to Import Verified Data to the Invoice Table"Style = vbYesNo + vbMsgSetForegroundTitle = "Verify Import"Response = MsgBox(Msg, Style, Title)If Response = vbYes Then 'This is the problem line DoCmd.OpenQuery "qry_Step_5_appending_invoices", acViewNormal, acEdit DoCmd.OpenQuery "Qry_Step_6_update_fob", acViewNormal, acEditElse MyString = "No"End IfEnd Sub
I have a "homemade" switchboard that I am using and the first page allows the choice of administrator or user. I have used access user level security to deny all but administrators access to the administrator "path" in my switchboard.
When a user clicks on it, they get the runtime error 2603 saying that they don't have access. I am trying to modify the on error event so that the error won't show up and a custom message box I create will show up instead, however I cannot seem to get my on error code to do anything. I always get the standard access runtime error return box. Does anyone have any ideas??
I have an "Error trapping" problem. I am relatively new to VBA and wondered if someone would be so kind and point out the error in my code.
I have a form "frmSelectInvoices" that opens another form, "frmInvoice".
I use the Select Invoices form to select completed jobs that are not invoiced, based on a query.
The user would then select a job that he/she wants to invoice, and "frmInvoice" opens in front of "frmSelectInvoice".
"frmInvoice" is based on "tblInvoices" and a couple of the required fields, (customer, JobID, etc) are filled-in automatically using the information from a couple of fields from "frmSelectInvoice"
"frmInvoice" also has an InvoiceNumber field which tblInvoices needs as it is set as a required field with no duplicates, (this is NOT the primary key).
I am trying to notify the user that the InvoiceNumber has already been used, and to reset the record, so they can enter a new Invoice Number.
The code I have so far is as follows; Code:Private Sub Notes_Exit(Cancel As Integer)On Error GoTo Err_SameNumber Dim iResponse As Integer iResponse = MsgBox("Do you wish to Print an Invoice", vbYesNo, "SELECT AN OPTION") If iResponse = vbYes Then DoCmd.RunCommand acCmdSaveRecord Forms!frmSelectInvoice!Invoiced.Value = True Forms!frmSelectInvoice.Requery DoCmd.Save acForm, "frmInvoice" DoCmd.OpenReport "rptInvoice", acNormal, "", "[pkInvoiceID]=[Forms]![frmInvoice]![pkInvoiceID]" Me.btnClose.SetFocus Exit Sub End If If iResponse = vbNo Then MsgBox "You can Print it out later from the Invoices Main Menu", , "You Selected NO" End If DoCmd.RunCommand acCmdSaveRecord Forms!frmSelectInvoice!Invoiced.Value = True Forms!frmSelectInvoice.Requery Me.btnClose.SetFocusExit_SameNumber:DoCmd.RunCommand acCmdUndo DoCmd.GoToRecord , , acNewRec Me.fkBookingID.Value = Forms!frmSelectInvoice!pkBookingID.Value Me.fkCustomerID.Value = Forms!frmSelectInvoice!fkCustomerID.ValueMe.InvoiceNumber.SetFocusExit SubErr_SameNumber: MsgBox "Invoice Number has already been used", vbInformation, "Please use a New Invoice Number" Resume Exit_SameNumberEnd Sub When I test the form with a number I know already exists, or even a number that has not been used before, the error message comes up and it then sets the focus to InvoiceNumber, but when I try and close the form it still keeps coming up and the only way I can get rid of it is to close the application using Windows Task Manager. Any help on this would be appreciated. Thanx
Hi guys, I was looking for a way to trap err.number 3314 (when required field is null) before Jet generates its warning. I came across an old post from Rich (below), but I couldn't make it work as yet. In the calling form, under the Form_Error event I wrote the following:
Dim f As Form Set f = Me Call fnValidateForm(f)
Could anyone please tell me where my error lays here? I have several forms which have several text and/or combo boxes bound to required fields and I would want to have a generic code, like the one here to trap errors before Jet shows it's Error Message.
Thanks in advance Regards Jaime Premy - Belém-Brasil
******************Rich's Function******************** Public Function fnValidateForm(frmA As Form) As Boolean Dim ctl As Control Dim Msg, Style, Title, Response, MyString fnValidateForm = True For Each ctl In frmA.Controls 'value in the control is required If InStr(1, ctl.Tag, "Required") > 0 Then ' no value entered or value is null ' or zero for numeric fields If (IsNull(ctl.Value)) Or (Len(ctl.Value) = 0) Then ctl.SetFocus MsgBox "You have not entered all the required fields return to the record and correct this! The record will not be saved if you do not! " fnValidateForm = False
Exit For End If
If InStr(1, ctl.Tag, "NumberRequired") > 0 Then If ctl.Value = 0 Then ctl.SetFocus MsgBox "You have not entered all the required fields return to the record and correct this! The record will not be saved if you do not! " fnValidateForm = False
I like having the action query warning appear with what I am doing - "You are about to update xxx rows". The problem that I am having is that when my RunSQL statement in the code executes and selects no to the warning, I get the error -
Run-time Error '2501' The RunSQL action was canceled.
How can I trap the no selection so that this vba error does not appear?
Ok, I have a delete query that I use to delete records form a table. I have created a form that I run that query from. It has Delete button that runs the query. After I get the message that says "You are about to delete 56 records" and I click No, I get a "run-time error '3059'. Operation Cancel by user"
I did some searching on the forum and thought I could trap this error. But I still continue to get the error at
"DoCmd.OpenQuery stDocName, acNormal, acEdit"
What am I doing wrong and how can I prevent this error from appearing when I click NO or cancel the operation.
Private Sub cmdDelete_Click() On Error GoTo Err_cmdDelete_Click
cmdDelete_Error: Select Case Err.Number Case 3059 MsgBox "You have canceled the delete operation.", vbOKOnly, "Delete Canceled" Exit Sub Case Else MsgBox "Error number: " & Err.Number & " has occurred. " & Err.Description, vbOKOnly, "Error" End Select
I've made my own record navigation buttons on a form. they work fine, except when i get to the first record. if i click 'previous' then the 2105 error pops up "you can't go to specified record". the buttons were created through the wizard, and have error trapping in them. for some reason, it never actually goes to the error handler. the error message comes up, i press debug, and the 'DoCmd.GoToRecord , , acPrevious' is highlighted.
any ideas why the error trapping isn't working? here's the code:
Private Sub cmdPrevJob_Click() Dim x As Variant On Error GoTo Err_cmdPrevJob_Click DoCmd.GoToRecord , , acPrevious Exit_cmdPrevJob_Click: Exit Sub Err_cmdPrevJob_Click: If Err.Number = 2105 Then stop MsgBox Err.Description Resume Exit_cmdPrevJob_Click End Sub
I've got my form working, and all of the record updating is working fine, so now I am working on error trapping. I need to check if any of the two textboxes are empty, or nothing has been selected from the combobox. I am using the BeforeUpdate method. I am not getting any syntax errors. I am using an INSERT INTO SQL statement. Thanks.
related DB fields: SOPNumber (text) RevisionNumber (text) TrainingDate (date/time)
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.cboSOPNumber) Then Cancel = True MsgBox "The SOP number is required", vbOKOnly, "Notice" Me.cboSOPNumber.SetFocus End If
If IsNull(Me.txtRevisionNumber) Then Cancel = True MsgBox "The Revision Number is required", vbOKOnly, "Notice" Me.txtRevisionNumber.SetFocus End If
If IsNull(Me.txtTrainingDate) Then Cancel = True MsgBox "The training date is required", vbOKOnly, "Notice" Me.txtTrainingDate.SetFocus End If
Hi guys i got a form and sub form. When i leave the field hours empty in the sub form and try to click on close or some where in the form i get this error:
MsgBox "Primary key violation", , "Explanation"
instead of
MsgBox "Violation of Not Null constraint", , "Explanation"
i want to trap not null error and prompt the user that he has to enter value for hours field but aparently it does not. i be happy if some one help me fix this error .Thanks
Code:Private Sub Form_Error(DataErr As Integer, Response As Integer)Select Case DataErr Case 3162 MsgBox "Violation of Not Null constraint", , "Explanation" Case 3146 MsgBox "Primary key violation", , "Explanation" Case 3155 MsgBox "Trigger violation: 'Wages of the employee in this project is not existed. You must enter data of hourly wage first'", , "Explanation" Case Else MsgBox "Other errors" End SelectEnd Sub
We are currently developing a simple Point Of Sale Form which consists of 2 text boxes and a list box.We need to trap numeric input from either the keyboard or a barcode scanner at form level,then setfocus on a textbox and enter the input into the textbox.So far have used the keydown event on the form to trap numeric input and setfocus using the following code.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode >= 48 And KeyCode <= 57 And KeyCode >= 96 And KeyCode <= 105 Then Me.Input.SetFocus End If End Sub
This does not however enter the keyboard or scanner input into the textbox.Is there a method to trap the input,set the focus and enter the input into the textbox once it has recieved the focus.
I am using following routine to lift data from Excel files into Access tables. Whole thing works, well, most of the time. The only issue I have is the spreadsheets are received from warehouses and even though they have been given strict instruction to stick to the template, I have had to adjust the spreadsheets. Amongst errors I get are:
Field 'F16' does not exist in table 'SA1'. (In this case I simply delete the last most empty column to fix this).
Or there are column name spellings and in such cases, I get no error and the simply code hangs.
Is there any routine that I could incorporate in the code that clearly states what issues are being experienced. This way I can pass the db to the user to run it themselves.
'Dim dbs As Database, tdf As TableDef Set dbs = CurrentDb On Error GoTo Macro1_Err DoCmd.SetWarnings False ' RunSQL executes a SQL string
What's the best way to trap the error I get when I don't input the time correctly in a date/time control?? I have a the following as an input mask: 99:00 >LL;0;_...02:30 PM
I am writing a small database using MS Access 2007. I have in it a function for running queries and printing reports. Printing works just fine if any one of the multiple query criteria is give.
I also want to trap errors and present a message if the user clicks the "Print" button without a query criteria. At the moment I only get a run-time syntax error message which has a "debug" button for accessing the entire code. I want a message that will say "There was no search criteria".
This is the code for printing:
Code: Private Sub cmdPrint_Click() Dim varWhere As Variant varWhere = BuildFilter ' Update the record source Me.RecordSource = "SELECT * FROM q_Vehicles " & varWhere
I have been working on a simple data base for some time now (beginner level) and am still trying to improve it. I would like to do something but before that I would like to have your opinion to know if it is even possible?I have a query QryMainReport:
Start Date/Time End Date/Time Employee
At the moment this is what the format of my report looks like (I removed other unnecessary fields):
StartTime----------EndTime---------------Employee 12/06/2014 01:00--12/06/2014 03:00------John Smith 12/06/2014 04:00--12/06/2014 06:00------Jane Doe 13/06/2014 02:00--13/06/2014 05:00------John Smith 13/06/2014 08:00--13/06/2014 08:00------Jane Doe
I would like to do as a report. (Dates would always be from Sunday to Saturday). I am not sure it is possible to do that. I suppose first it would mean:I would have to do a query to separate the times from the dates?I would have to find a way for Access to find the unique dates and unique names?Does it mean I have to use cross tab queries?
:confused: Anyone know how to trap/prevent the msg "The DoMenuItem action was cancelled" after answering no to deleting a record? I followed the instructions at the following thread but no luck:
---------------------------------- Private Sub Delete_Click() On Error GoTo Err_Delete_Click DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 Exit_Delete_Click: Exit Sub Err_Delete_Click: MsgBox Err.Description Resume Exit_Delete_Click End Sub
----------------------------------- Private Sub Form_Delete(Cancel As Integer) DoCmd.SetWarnings False If MsgBox("Are you sure you want to delete this record?", vbYesNo) = vbNo Then Cancel = True Else MsgBox "Record deleted!" End If End Sub -------------------------------------
Private Sub NextApplication_Click() On Error GoTo Err_NextApplication_Click DoCmd.GoToRecord , , acNext
Exit_NextApplication_Click: Exit Sub
Err_NextApplication_Click: If Err.Number = 2105 Then MsgBox "Cannot navigate to the next record. This is the last record." Else MsgBox Err.Description End If
Resume Exit_NextApplication_Click
End Sub
but even when this error occurs nothing is being properly handled the way i specified - any ideas ?
I am just about to start a new DB, but there are a few things I need to sort before i start.
I am working with a quotation system etc which will require the use of unique IDs...
eg 000123 then 000124 etc, this bit is not a problem. The thing I would like to know how to do is when someone makes an order, I would like the quotation number to be changed slightly to add more detail. For eg, If the quotation number that is allocated is 00123 and they then order a Conservatory, I would need to have this 00123 become 00123CNS, but this can be in a seperate field, Which I would need anyway.
The question is, How Would I go about this. I have a table that describrives the product, TBL_PRODUCTS; ID, Product_Type, Product_ABBR
Product_Type = for e.g Conservatory Product_ABBR = for e.g CNS
I would need the ref number and product abbr combined to create an order number. [note] There will be a check box to say of ordered ot not, so I assume there will be an If statement somewhere?
What I've done is created a form based on the tbl_customer table and used tbl_rates as a sub form. tbl_destination is used to populate a combo box that is situated in the sub form.
Each customer has their own rate sheet. Each rate sheet has different destinations and rates. Rates for the same destination are constantly changing. I need to use this spreadsheet to record the history of every change made to the rates of a particular destination. To do this I've just added the same destination with a new rate.
Now, what I want to do is to create a query that will only show the latest entry of a particular entry.
So I've read a good 100 postings or so so far on the subject of how generating a unique identifier through any other means than an autonumber can be dangerous. But I can't resist the opportunity to simply ask if there is a way to make this possible, if only through a calculated field...
In my single user database, I have an employment table with an autonumber [EmploymentID] field as its primary key. The employment table exists in a one-to-many relationship with it's child, the income table where each form of income is recorded as it is recieved so that one form of employment (or employer) can produce many unique forms of income (like weekly paycheques).
I would like to be able to generate an identifier for the income table that is a combination of the parent [EmploymentID] field and an increasing number to produce something that looks like this:
1006789-001 -| 1006789-002 -|--> Same EmploymentID 1006789-003 -| 1006790-001 ----> New EmploymentID with a reset numeric
I've data already entered (access/tables) on two different computers, however for the clientid on one computer has a hypen (-) and on another - because of something they couldn't get the hypen to work - so they used the slash (/) my Q is: 1) can I search and convert these to one, 2) is it wise the have / or - in the id?
I am very new to db programing so please forgive for such a simple program.
Here is the deal. I have a db for about 500 students.
I would like the table [Students] to create a unique ID "number" for each student. I would like the number to be based on information from the same table. For example if the student's name is John Doe and his number is 555-1212 then I would like to the id to be JD1212. I plan on using more than name and phone number but this was just to show you, what i am trying to get done.
I can do this using a form and a calculated control, but I can't get the table and form to kiss and make up. I was also told you can't save data from a calculated control in a form to a table and it is gernerally not a good idea, so I was told.
I have thought about this for days now (and nights) and I have simplified my problem below. (I even bought a book) I have three tables: 1, 2 and 3. Table 1 = a, b and c Table 2 = x, y and z Table 3 combines table 1 and table 2; ax, ay, az, bx, by, bz, etc. Table 1 and Table 2 are both One to Many with Table 3. The Table 1 field and Table 2 field are a ‘unique’ index combination. My Problem: It would be very handy to produce a list of the ‘unique’ index combinations that are not in Table 3. That is, the ‘unique’ index combinations that aren’t used yet. You could do this by trial and error, but is there a Query you can run that will give you a result that you could then Append? An Unmatched Query on the Table 3 / Table 1 contents will point out a complete lack of either a, b or c as will the same Query on Table 2 for missing x, y or z. A query with the two non-linked tables will give every combination, but is this the best way to do it? It works by default when you use it to append table 3, but is it the best way to do it?