I would like help with a macro that looks to see if a record in my database table exists, then if it doesn't it adds a record with my data, but if the records does exist, it stops the routine and sends a message box to prompt if you want to continue with adding a new record.
The problem that I'm having is that my macro errors out when it doesn't find a record. I just want my macro to just see if a record exists or not. Then I can write my Iff statements based on whether it finds our or not. How do I just have my macro check for an record, then if it doesn't exist tell that it doesn't exist and not stop my macro. Is there some kind of IfExist() function or something?
I put a Dlookup function to compare the new entry in a form and the code is like this:
If (Not IsNull(DLookup("[empno]", "Attnd_tbl" , "[empno]=[empnotxt]")))then MsgBox "This Employee Already Exists" cancel = true Me!empnotxt.undo end if end sub
this works for comparing one field only, since I want to check if the employee is already entered on a certain date, how do I put two fields in this function to be looked up if for example "[empno]and[date]","Attnd_tbl","[empno]and[date]=[empnotxt]and[datetxt]"
I found and modified this code to allow me to check (fast) if a file exist on a http server or not (without downloading it).
Code: Public Function CheckNetFile(WebFile As String) Dim XmlHttpReq As Object Set XmlHttpReq = CreateObject("Microsoft.XMLHTTP") XmlHttpReq.Open "HEAD", WebFile, False
[Code] ....
In the above code I managed to declare Webfile as a string so I can call on it later but one thing I still need to tweak is to also get a result out of the test code in a better way than having to publically declare the "CheckNet" variable somewhere else in my app.
First prize would something like this:
If CheckNetFile ("http://www.mysite.co.za/test/test.txt") = 1 then "Yes" else "No"
How do I build the 'booleon check' into the original function?
I'm trying to write some Code with the target to take a value from a textbox (out of a form) and a pregiven value (in this case = 2) and enter them in a new record in a table. But only if there is not already a record with the exact same combination of these to values. When done, the same button should proceed you to the next form (but this code is not already implemented in the fragment below) even if no values are added because they already exist in this combination.
Code: Public Function GetID_PatientStudiesGroup&() GetID_PatientStudiesGroup = [Forms]![frm_PatientStudiesGroupTZP]![ID_PatientStudiesGroup] End Function Private Sub BPRS_T1_Button_Click() Call GetID_PatientStudiesGroup& Dim strSQL As String
[Code] ....
As you can see, I tried to use a function to refer to the value out of the form, because I didn't find out how to refer to a form in an SQL Code.
Just to give you a better overview: The table where the information should be added is named "tbl_PatientStudiesGroupTZP". The form where you find the Textbox "ID_PatientStudiesGroup" (with the value I need to transport) is named "frm_PatientStudiesGroupTZP". Every part (except the WHERE NOT EXISTS part) worked perfectly for itself, but not when thrown together.
I have a parent form which has a yes/no checkbox in the form's record source. Then in that parent form I have a sub-form. If NO records exist in the sub-form I want the checkbox to be UN checked. If records DO exist in the sub-form, I want the checkbox to be CHECKED.
But I want this to happen as records are added or deleted from the sub-form. In other words, if the parent form is opened and no records exist in the subform then the checkbox should be unchecked. But as soon as the first record has been entered in the subform, the checkbox on the parent form should be checked. Likewise, as soon as the last record has been revoved from the sub-form, the checkbox on the parent form should be unchecked.
I have a problem with my database I have a combo box that will search for my record. Actually its working I input the specific number it goes to the specific record. But I want, if there no existing record in my database it will display a Messagebox that "No record Found" I try to put a code in a macro builder in a after update property field but nothing happened.
Expression code that it will display the msgbox if there's no record found.
the given code from macro builder is attached. I try to have an if else statement but I dont know how to not equal that giver conditional expression.
What I've done is setfocus from another subform to this subform, and I want to add a new record. I've got my code mixed up somewhere along the line as it's saying "the command or action 'RecordsGoToNew isn't available now.I'm trying to setfocus to this form, create a new record and setfocus to a field within the focussed form.
I'm using the following code to autofill the city and state on my form. I can't figure out how to capture if there is no matching record in the table. If there is no matching record, I will:
1) inform the user with a msgbox then if the user wants 2) open a form to add the record to the table
Dim rst As DAO.Recordset Dim db As DAO.Database
Set db = CurrentDb Set rst = db.OpenRecordset("tblZipcodes", dbOpenTable)
rst.MoveLast rst.MoveFirst
Do Until rst.EOF
If strZipLookup = rst!ZipCode Then Me.txtCoCity = rst![ZipCity] Me.cboCoSt = rst![ZipState]
End If
rst.MoveNext
Loop
rst.Close End If
How can I capture if there is no matching record in the table?
I have set up a simplified event booking procedure, similar to the one generated by the access event manager wizard. It uses three tables, one with attendees details, one with the event details and abooking table that links the attendee ID with the Event ID.
The booking table uses commands similar to SELECT[Names + Contacts].[ID],[Names + Contacts].[Surname]FROM[Names + Contacts] to generate drop down lists of surnames and events so that the two can be matched together.
This works fine as a table.
However when placed into a form, whenever the form is opened I get an error message saying the record source specified on the form does not exist.
I have tried regenerating the form, etc. I have used a wizard to generate the form, closed the form, not changed anything in the database and then tried reopening it and I get the error message, can anyone shed any light?
Also if you accept the message then it knows how many records there are, so it must know there's something behind it, also if you change to design mode and then back to form mode, it finds all the data.
I have a training database with multiple courses. Certain staff do course1 and thereafter course2. Course1 is only done once and course2 is a refresher done annually. I want the query to find staff that have done course2 but not course1.
I have a table that is filled based on selections that a user makes in combo boxes on a form. I am having trouble trying to figure out the best way to prevent duplicates from being inserted in the table when I do the append query part.
Since the table is filled based on the various selections the user makes I dont have a primary key or unique field.
Can someone help me figure out the best way to do this append/update queries to prevent duplicates. Also if you have a strategy for setting up some sort of unique or primary key for fields that could all be the same yet in the table only 1 record will show, no duplicates.
I have an application written in Access 2007 and packaged using the Packaging Solutions for deployment with Runtime.My problem is that I've written an updated version, and after carefully saving my original Back End away from the install site, uninstalling Runtime and the FE, installing the new FE with a blank copy of the BE having the same name and Runtime, and copying the filled BE into the same folder with the FE (replacing the linked, but empty, BE) I find that SOME of my tables in the BE are not being recognized. This isn't true of all tables. I can open some of the forms and find everything there. In other cases I get the following error message "The record source "tblName" specified on this form or report does not exist."
I currently have this set as the forms default recordsource (which works just fine):
Code: SELECT TOP 5 tblUsers_Phone_Book.EMAIL_ADDRESS, weightedDL('me@mine.com',[EMAIL_ADDRESS]) AS Expr1
And I have this vba to dynamically switch around that email address.
Code: Private Sub Form_Load() Dim intPos As Integer Dim strControlName As String Dim strValue As String Dim sSQL As String If Len(Me.OpenArgs) > 0 Then ' Position of the pipe
[Code] ....
If I msgbox the sSQL - it shows identical to the default recordsource but I get the error:
The error message I get is:
Run-Time error '2580' The record source 'SELECT TOP 5 tblUsers_Phone_Book.EMAIL_ADDRESS, weightedDL('me@mine.com',[EMAIL_ADDRESS]) AS Expr1' specified on this form or report does not exist.
I tried copying the exact working default sql into the vba and get the same result.
I have an application that enters candidates in, who apply for a job.
I found that I can enter a candidate in, and if I dont enter at least an address type or phone type ( giving that candidate an address record, albiet a blank one (just a type of address) and a phone record) then the candidate wont have a sub record for addres or phone at all.
This is hurting my reports. They are set to pull the primary address and phone only, as we dont need to have 2-3 contact information for a candidate on a report This is how I found out that I had blank address and phone for some test records. I need to be able to check when a person does a number of things, that at least the combos for phone type and address type have been chosen as something. This will ensure that they have a primary address and phone, as I have code that takes care of all that. I tried putting the following code in the form's before update, but since it is calling to a subform, the minute I tab TO the address combo, I get the message. The form is updating before I get the chance to skip the field.
Here is the lay out. A user can enter in candidate, their address, phone, application and activities. Address, phone, applications and activities are all sub reports on a tab control. The user should be able to move freely within any record, and only be bothered when they try to leave, if important information is still empty. I dont want to control how they enter ('you must enter this first!' lol) just that they do enter it in the end.
What I want to do is check when the user is leaving a record.(closing form, going to another record, clicking the search button that opens another form etc) if either combo is empty (no primary contact info) then it gives the message and goes back to the combo that is empty.
Here is the code I have. If anyone can help me find the right place to put it, I would really appreciate it. Thank you,
If IsNull(Me.[subAddressEntry].Form![cmbAddressTypeID]) Then msgbox "You must enter an Address" Me.[subAddressEntry].Form![cmbAddressTypeID].SetFocus Cancel = True ElseIf IsNull(Me.[subPhoneEntry].Form![cmbPhoneTypeID]) Then msgbox "You must enter a Phone" Me.[subPhoneEntry].Form![cmbPhoneTypeID].SetFocus Cancel = True Else: Cancel = False End If
If I can't figure this out, I am thinking of making a new address type and phone type. Call it "none chosen" and then make that a default selection. Then one would always be chosen...I think. I would like to avoid that though.
I'm sure the coding is very simple, the question is .... can I build an expression using an IIF statement that checks whether the current field is the same as the same field in the next record? If it is put a 1, if not put a 0. Easy in Excel, not sure about Access??
i would like to check a record exits before a new entry is saved. However i would like to check on three criterias and i am not sure on how to write the if statement.
IF Dcount "CompanyName" & "FirstName" & "Last Name" from "tblcustomer" is the same as "frmCompanyName" & "frmFirstName" & "frmLastName" > 0
I am running a check for checking whether a value already exists in the database table. But the problem is that the control passes right through this check.
It does not give an error too...
If txt_id.Value = DLookup("id", "indicateur", "id=" & txt_id.Value) Then info = MsgBox("Cette 'Id' déjà existe !", vbInformation)
I need to know how to check if there is a record set matching a name and insert record if there is not one, otherwise just update if a record does match. See code: Code:<%Name = request.form("name")picture = request.form("picture") opencnset rs = Server.CreateObject("ADODB.RecordSet")'if no record matches the nameSQL1= "INSERT INTO background (Name, Picture) VALUES ('" & name & "', '" & picture & "')"'elseSQL1= "UPDATE background SET Picture = '" & picture & "' WHERE Name= '" & name & "'"cn.Execute SQL1closeCN%> Thanks in advance for any help you all can provide!!!! -Chris Gordon
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 ?
How do you make the spell checker not cycle through all your records when you run it? As it is right now, when a user tries to spell check their entry into the summary block of my form it automatically starts with the first record in the database and goes from there.
I have 2 forms, with a "PNID" field as the link between the 2. In the 2nd form, the PNID field allows no duplicates. I have a button on the first form to open the 2nd form to add a record.
I need some code to put on the button on the 1st form to check whether a PNID record exists on the 2nd form before opening it.......does this make sense? What is happening is that I click on the button, try and add a record, then it tells me one exists and I cannot add a duplicate...
I have looked at the threads, and have tried using DCount? Is this correct?
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.