473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Table check from Form

Abhean
32
Ok I am not good at forming my questions. I am attempting to check for existing records from a table (Client) specifically from (CAccount) field on that table. The form I am working in is based on another table (DoSService). The txtfiels on the form is (DoSLocation).

I keep getting an error at the .findfirst line. What am I forgetting or missing?

Expand|Select|Wrap|Line Numbers
  1. Private Sub DoSLocation_AfterUpdate()
  2. Dim db      As DAO.Database
  3. Dim rst     As DAO.Recordset
  4. Set db = CurrentDb()
  5. Set rst = db.OpenRecordset("Client", dbOpenDynaset)
  6.  
  7.     With rst
  8.            If Not (.BOF And .EOF) Then
  9.                Call .MoveFirst
  10.                .FindFirst "CAccount = '" & Me!DoSLocation & "'"
  11.                If Not .NoMatch Then
  12.                    'Found it!
  13.                    MsgBox "found the record"
  14.                Else
  15.                     MsgBox "Did not found the record"
  16.                     'DoCmd.OpenForm "Client_Frm", acNormal, , , acFormAdd
  17.                    'Call .Update
  18.                End If
  19.            End If
  20.            Call .Close
  21.        End With
  22.  
  23. End Sub 
Jun 17 '20 #1

✓ answered by twinnyfo

Abhean,

First, what is the error that you are receiving? That is more instructive to us than anything else.

Second, it might be as simple as replacing line 10 above with:

Expand|Select|Wrap|Line Numbers
  1. .FindFirst "CAccount = '" & Me.DoSLocation & "'"
(replace the bang (!) with the dot (.). In some instances either delineator will work. This might be one of those cases in which it does not.

Thirdly, if CAccount is a numerical field, you will throw an error as you are trying to search for a text value. In that case, your syntax should be:

Expand|Select|Wrap|Line Numbers
  1. .FindFirst "CAccount = " & Me.DoSLocation
Finally, some free advice. It is always wise to rename the controls on your form to a different name than the fields that underlie them. This can avoid ambiguity--and Access loves things to be more explicit in most cases.

Hope this gives you a few options to try.

Hope it hepps!

4 1868
twinnyfo
3,653 Expert Mod 2GB
Abhean,

First, what is the error that you are receiving? That is more instructive to us than anything else.

Second, it might be as simple as replacing line 10 above with:

Expand|Select|Wrap|Line Numbers
  1. .FindFirst "CAccount = '" & Me.DoSLocation & "'"
(replace the bang (!) with the dot (.). In some instances either delineator will work. This might be one of those cases in which it does not.

Thirdly, if CAccount is a numerical field, you will throw an error as you are trying to search for a text value. In that case, your syntax should be:

Expand|Select|Wrap|Line Numbers
  1. .FindFirst "CAccount = " & Me.DoSLocation
Finally, some free advice. It is always wise to rename the controls on your form to a different name than the fields that underlie them. This can avoid ambiguity--and Access loves things to be more explicit in most cases.

Hope this gives you a few options to try.

Hope it hepps!
Jun 17 '20 #2
Abhean
32
It is telling me Datatype mismatch in criteria expression.
both data sets are number.

BAM! the 2nd code snippet worked like a dream.

And thanks for the advice. I am having to relearn access once again. :)
Jun 17 '20 #3
NeoPa
32,556 Expert Mod 16PB
The error message is nearly always the most helpful information in a question.

There doesn't appear to be anything fundamentally wrong with the syntax of your code. Obviously the criteria used has to match the Tables and Fields as defined in your database so we would need the detail of that before we could properly check that the format of the criteria makes sense for your situation.

I suspect with that information available any issues would be easily resolvable.
Jun 17 '20 #4
NeoPa
32,556 Expert Mod 16PB
Ah. That makes sense.

That error message is telling you that the type of the comparison value (Text) is not compatible with the referenced Field. That indicates that [CAccount] must be non-textual. Numeric or date/time.

The fact that Twinny's suggested code works confirms the Field is numeric.

You may find Quotes (') and Double-Quotes (") - Where and When to use them to be helpful in order to get a good understanding of why certain ways of doing things are necessary.
Jun 17 '20 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mike S. Nowostawsky | last post by:
I need to be able to create a 2 column table and then based on which column header is clicked on, sort the list by that column so that each table row is sorted properly. If possible there might be...
2
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple...
2
by: Dknight | last post by:
Hi, all! I have a problem, how can I check a form data before sending it to server. I have the example below, but first data is sent to server, but after JavaScript checks the data :( I need...
4
by: yanjie.ma | last post by:
Hi, I've got a two part question on table and form design (sorry for the length but it takes a bit to explain). Our sales department uses a look-up table to help the them select the best...
1
by: Ste | last post by:
Hi, I would like to have current date automatically enter into a form that is based on a table, so that from report I can tell how many records I have entered for the day. If I use date() on...
2
by: thread | last post by:
Hi, is it posible to get the size of the table,query and form in the file so it will be easy to estimate what is taking the most space of the file?
11
by: flametail | last post by:
I have a php script that shows all the data in a table. I want it to have check boxes next to each line of this data that it puts out, so I can check the boxes next to certain entries, and when I...
1
by: Joanna c | last post by:
I am new to Access 2007. I have used a MS template (student Database) i have successfully made minor changes. Have made a query to state exact age however cannot get the age to appear in the table or...
4
beacon
by: beacon | last post by:
Hi everybody, I have three tables: tblForms, tblFormDeficiency, tblDeficiencyType. The tblForms and tblDeficiencyType have a many-to-many relationship with each other with tblFormDeficiency...
1
by: zeusads | last post by:
Hello, I have a little problem, if anyone can help! I have these 2 tables Products: ID Product Category Current Stock
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.