On Lost Focus....check To See If Primary Key Exists
Jul 20, 2005
I recently have been given a database to get into shape.
One of the main problems is that when a person enters data into a form, They until the leave the form are not aware if the primary key has been used before.
Let me try explain.
I have a booking number (which I have only in the last couple of days made a primary key and also changed it so there can be no duplicates)
I have changed the form around alittle so that the person entering the new data must start with entering the booking number.
How can I make a piece of code that once the booking number textbox loses its focus the code then checks the table to see if that booking number exists. I would like for the person to establish that they need to enter a new booking number before getting to the end before seeing that the booking number already exists.
I have a form and on open it traps the user into a combo box where an option must be selected before they can move to another field. I did this by using the lost focus event of the combo to check if an option has been selected and then return the cursor to the combo if no selection has been made.
The problem is that there is an exit button on the form which the user must be able to use to exit the form without interacting with it, say if they opened the form by mistake and just wanted to exit immediately.
I cant find a way to trap users into selecting an option from the combo before filling the rest of the form while still allowing the exit button to work. At the minute you still have to select an option in the combo even if you just want to exit the form.
I have been a notes developer for years so Iím still not that familiar with access and the way its events work so this could easily be a gormless question. Feel free to point that out. Any comments would be much appreciated.
I'm having lots of erratic problems with our Access database. Back end tables on the server, front ends on workstations. Running Windows 2000 server, Access 2003 SP2 on Windows XP SP2. I'm not the network administrator so don't have much detail on network. For instance, the back end is 'losing' relationships between tables, with the primary key on the 'one' end of a 'many' relationship disappearing - the relationship link between the tables also disappears. Other errors are:- erratic problems with indexes which are sometimes fixed with a compact / repair, sometimes not- data on forms disappearing- data on forms appearing in the wrong field- queries that ask for parameter input twice when only programmed to so once- sorting orders suddenly going wrong way round - inability delete a record via a form, caused Access to completely crash with Microsofts 'sorry unrecoverable error' message. To fix the query problem, I created a blank query and imported the old one into it, problem solved. But what caused the old query to act weird in the first place?To fix the inability to delete a record problem, I created a whole new blank database and imported everything into it. But what caused the database to repeatedly crash? The suddenly missing relationships I have no cure for. I'm at the end of my tether - can't figure out any pattern to this. Any suggestions? Network errors? Read / write on server? Disk space / fragmentation? Fundamental problem with the database?Any help much appreciated.Sorry if this post should have been in the tables forum.
Hi, I have the following problem which I hope someone can help me with:
I have a form which is used to enter data into a table. One of the fields is 'Code'. I want the form to check when data is enetered into this field is it already exists, ie if the code is already present in the 'code' field in the table, and if it is it should give a warning message, if not then continue as normal.
Any help would be greatly appreciated, thanks in advance!
I have a form used to enter new contacts. I would like to insert a query or macro that would automatically to see if the name (first and last) already exists in the table to which this form is attached. If the name exists, I want to open the existing record and add information to it. If not, I want to enter the information as a new record.
I have a problem where a user would enter a project code eg 113-099. I put in a list box that filters all the project codes for instance if the user enters 1 it will show all codes starting with a 1 and every additional number they enter it filters the list box to show which codes already exists! I hope this makes sense.
The problem i have is i need to check when they enter the project code that it is a unique value. The Database developer we got in didnt index this field as no duplicates allowed and as result we have large amount of duplicate project codes.
I have started to experiment with Dlookup but with no great success.
If anyone can help it would be much appreciated as i dont have much experience with access.
The field name on the form is
[forms]![projects_frm].[project_job_number] and the table which stores this information is [projects]
Is there any way to check if a particular table already exist in MS Access Database using ACCESS VBA?
Actually I'm creating temp table on the file but I want to check if temp table already exits then need to delete before creating.
e.g. I can check if query defniniton already exists using below code:
Code: If .DCount("[Name]", "MSysObjects", "Left([Name],1) <> '~' AND [Type] = 5 AND [Name] = '" & strTempQueryName & "' ") <> 0 Then .DoCmd.DeleteObject acQuery, strTempQueryName .CurrentDb.QueryDefs.Refresh End If
Hello all, I have a form that looks at my "master table" where users put in general info about a sheet of material. There are two combo boxes on this form, Batch# and Lot#. They will use the same Batch# and Lot# for many sheets. Every time a new batch and lot are entered, this will bring up a pop-up form where the user needs to take a measurement of that batch and lot for QA. This will go into a different table, where the batch and lot #'s are unique(many of the same batch#'s with different Lot#'s). After the lot# is entered, I want to run a query in VB that looks for those unique identifiers, and if it doesn't find a record, my pop-up form will run. This is probably something very easy....... It was a very long weekend and I'm tired of thinking.
For a couple of days now I've been trying to devise a way to achieve what I want, but I just keep going in circles and hitting errors (thanks to forum members, I've been able to solve most of them.) So, here's what I want to be able to do:
Input a product using the iproduct combo box (which gets its list of values from the Products table); its brand, using the ibrand combo box; and its size using the isize textbox, all in the frmFoodSub form. I then want it to check to see if an exact record already exists (ie. the same product, same brand, same size.)
If it doesn't exist, I want to create it. If it does, I want to do nothing. Then I want the product - either the one I just created, or from a record that already exists matching the iProduct input - to be input into the product field of the PurchaseDetails table. I then want to use iQuantity and iPrice textboxs, already linked to the PurchaseDetails table, to input the newly added product's quantity and price.
I hope my explanation was clear enough. I'd appreciate any help with this you may be able to offer.
I have created a form which enbles users to enter data into the fields which will add a new record to my table. What I am trying to do now is to create some kind of validation rule that will check whether the record already exists.
I need it to work this way; there are four input fields- 3 text and 1 is a date filed. When the user enters a new record they are not allowed to create a record that conatins the same combination of values. So if one record has for example filed 1 = 1 field 2 = abc field 3 = def; then no other record can have the same combination of values.
If the user enters an already existing combination there would be an error message saying which field is incorrect. If the combination doesn't exist it would add the record and display a message that the record was successfully added.
I have a table with several thousand records. Each record as a path field that indicates a specific file that is associated with a given record (not just a directory, it identifies a specific file). I'm pretty sure that most of them are correct but I've seen and been cleaning up paths that have had typos in them or were otherwise not setup correctly. Is there a way that I can generate a report or a list of some sort that would tell me exactly which file paths exist and which ones don't? or even just the ones that don't.
I have an application that I have automatically checking to see if tables are valid and connected, etc. If the app finds that the tables aren't connected or aren't working, it automatically tries to re-connect those tables in the background without the user's knowledge. The time I'm having trouble is if the SQL Server doesn't exists (the back-end tables are on a SQL Server). I would like to check to see if the SQL Server exists before I try to re-connect tables so that no SQL Errors pop up but I'm not sure how to figure that out with VBA.
I have a form, which has a combo box which a user can select an employee - the combo has three columns (Employee_Number, Surname, Initials) although the Employee_Number column is set at a 0 width, so not visible.
The form is bound to a query which only shows records that are 'Active'
When a user selects and employee in the combo box, I want the AfterUpdate event to check and see if there is already an active record - if there is, throw up an error message and then reveal a couple of buttons giving choices what to do next; if there isn't an active record, reveal three textboxes and then populate those textboxes with the values from the three columns from the combo.
The bit that is sticking me is the search - - I have tried DCount, but can't seem to get it to work
Here is the section of code that I am battling with:
Code: Dim EmpNo As String EmpNo = cboEmp_Check.column(0) If DCount("Employee_Number", "Incomplete_Training", "Employee_Number=" & EmpNo) > 0 Then MsgBox "Existing", vbOKOnly
i'm trying to do something that i thought would be pretty simple. what happens is i have 2 files that get used, one by access and one by excel. they are both the same, except if one gets modified then the other doesnt obviously. (theres reasons for having the 2 files).
anyway. in access i want it to pick the newer of the two files (i assume this is using a fso system object?), if the one it normally doesnt use is newer, it should copy the new one over the old one and continue using the one it normally uses.
i cant simply use the other file as another user always has that file open.
any sample code on how to check if things are modifyed at a later date? and copy/pasting using those fso objects?
Background: In my Access FE, I have created a "linked table" to a file on our AS400 database. I know I can check the MSysObjects table for the linked table name, but sometimes the file actually does not exist on the AS400.
The file can be in one of three states.File exists with data.
File exists, but is empty.
File doesn't exist.
Question: What is the best way to determine the status of this linked table (file)?
I can already send emails out as PDF files when an email address exists, however, I'm trying to validate whether or not an email address does actually exist. My problem is, there are four possible locations where an email address could be: MainEmail or Contact1Email or Contact2Email or Email (the last one - Email - is in a separate table).
Four text boxes exist on the form that is being actioned (the form is based on a query to extract the relevant information) and are available to test for an email address being present. What I'm struggling with is ensuring that the 'To' box in Outlook always gets populated or Outlook chucks a hissy fit. I have been trying various IF Then Else and Do Loop plus a myriad of other ways but none are reliable, especially if no email address is present which can be the case.
I have code working for some workers here ,who used to save excel files in a folder and my databse upload those files into database and then do the rest.I am looking for a code in vba which,on upload button matches the file in table and if the file already exists ,it should not upload again in the table and if it does not exists it should upload . I have attached my code below :
Private Sub Command0_Click() Dim strcPath As String strcPath = "O:QA FilesQC ReportingPending Review" Dim strcNewPath As String
The problem I have is, that I need to insert an apointment into de database but first I need to verify if there is a record or an apointment in that room that day the same hour, if that is so send a msgbox saying an apointment already exist in that room this day at this hour.
i tried using dlookup but it only works in one record using just one criteria
I have a module that I am using to verify that file paths in my table point to valid jpg files. The table has grown quite a bit since I first created the module and it has gotten to the point where it's taking too long for the module to execute. I'm in the process of trying to change the record set for the module from the table to a stored query procedure but it's turning out to be a little tricky for me. When I execute the following module, I'm not getting any error code, it just doesn't seem to do anything at all. The bits in red are the parts I've changed. Before that the module executed as I expected it would.
Sub TestIt2() Dim strFileName As String Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb() Set rs = db.OpenRecordset("QryUpdateRevisionHistory")