473,473 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Search a table / field if a value is present

84 New Member
God this is annoying me, im sorry if this has been asked before but ive looked though the forum and the net but my searches havent come up woth anything.... mainly due to that i dont really know what to search for.

So here we go, i have a table in access called hopper that hold some info about a feed hopper ( max volume , feed_ID etc) i also have a table called feed which holds "feed_ID , Catagory" now i want to be able to add a new hopper to the hopper table, i have done that and it works fine but the part im stuck on is i want to check if the Feed_ID entered when creating the hopper is contained in the Feed table. ive been trying to use if and if not statements but im getting all mixed up :D


i hope someone can help :D and i think its kinda simple to do, but as i said i dont know what to search for :(
Sep 27 '07 #1
7 2256
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Open a Recordset to check ID is present or not :
use this SQL

sSQl = "Select * from MyTable Where ID =" & variablename

if u get RS.eof then (Not Present)

Regards
Veena
Sep 27 '07 #2
metalheadstorm
84 New Member
ty for your speedy responce, i had a go at the but being pritty much a noob @ vb :D

this i what i came up with:


form load

Set db3 = OpenDatabase(App.Path + "/cjmillers.mdb")
Set rs3 = db3.OpenRecordset("Feed")


'----------------------


Private Sub Command28_Click()
If txthopper(0).Text = "" Then
MsgBox "Please enter a Hopper ID", vbInformation, "MMS"
txthopper(0).SetFocus
Else
If txthopper(1).Text = "" Then
MsgBox "Please enter a Hopper Number", vbInformation, "MMS"
txthopper(1).SetFocus
Else
If txthopper(2).Text = "" Then
MsgBox "Please enter a Feed ID", vbInformation, "MMS"
txthopper(2).SetFocus
Else
If txthopper(3).Text = "" Then
MsgBox "Please enter a Catagory", vbInformation, "MMS"
txthopper(3).SetFocus
Else
If txthopper(4).Text = "" Then
MsgBox "Please enter a Maximum Feed", vbInformation, "MMS"
txthopper(4).SetFocus
Else
If txthopper(5).Text = "" Then
MsgBox "please enter The Feed Left", vbInformation, "MMS"
txthopper(5).SetFocus
Else

rs2.AddNew

txthopper(0).Text = rs2.Fields(0)
txthopper(1).Text = rs2.Fields(1)
txthopper(2).Text = rs2.Fields(2)
txthopper(3).Text = rs2.Fields(3)
txthopper(4).Text = rs2.Fields(4)
txthopper(5).Text = rs2.Fields(5)

rs2.Update

'-----------------------
Dim sSQL As String

sSQL = "Select * from Feed =" & Feed_ID


rs3.RecordSource = sSQL
rs3.Refresh
rs3.Recordset.MoveFirst
Do Until rs3.Recordset.EOF
rs3.MoveNext
Loop
End If
End If
End If
End If
End If
End If
End Sub


im now getting an error "94"

from txthopper(0).Text = rs2.Fields(0)

im not sure if the code for

Dim sSQL As String

sSQL = "Select * from Feed =" & Feed_ID


rs3.RecordSource = sSQL
rs3.Refresh
rs3.Recordset.MoveFirst
Do Until rs3.Recordset.EOF
rs3.MoveNext


is correct, plz comment :D

thanks once again.
Sep 27 '07 #3
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

it shud be:
replace Table_name with ur table name
and Var_Feed_ID with ur variable name


sSQL = "Select * from Table_name Where Feed_ID =" & Var_Feed_ID
set rs3 = db3.Openrecordset(sSQL,dbOpenDynaset)
If rs3.RecordCount =0 Then
'ADD new Code here
Else
'Msg Box for duplicate entry....
End If



Regards
Veena
Sep 27 '07 #4
metalheadstorm
84 New Member
ok this is what i got

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Set db = OpenDatabase(App.Path + "/cjmillers.mdb")
  4. Set rs = db.OpenRecordset("Orders")
  5.  
  6. Set db1 = OpenDatabase(App.Path + "/cjmillers.mdb")
  7. Set rs1 = db1.OpenRecordset("Orders")
  8.  
  9. Set db2 = OpenDatabase(App.Path + "/cjmillers.mdb")
  10. Set rs2 = db2.OpenRecordset("Hopper")
  11.  
  12. Set db3 = OpenDatabase(App.Path + "/cjmillers.mdb")
  13. Set rs3 = db3.OpenRecordset("Feed")
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command28_Click()
  2.  
  3. SQL = "Select * from Feed Where Feed_ID =" & txthopper(2).Text
  4.  
  5.  
  6. Set rs3 = db3.OpenRecordset(sSQL, dbOpenDynaset)
  7. If rs3.RecordCount = 0 Then
  8. rs2.AddNew
  9.     txthopper(0).Text = rs2.Fields(0)
  10.     txthopper(1).Text = rs2.Fields(1)
  11.     txthopper(2).Text = rs2.Fields(2)
  12.     txthopper(3).Text = rs2.Fields(3)
  13.     txthopper(4).Text = rs2.Fields(4)
  14.     txthopper(5).Text = rs2.Fields(5)
  15. rs2.Update
  16.  
  17. Else
  18. MsgBox ("Feed ID entered does not exsisist")
  19. End If
i get a error on line
Set rs3 = db3.OpenRecordset(sSQL, dbOpenDynaset)

i think its just that im tired :D all this text is just a blur tbh :D
Sep 27 '07 #5
metalheadstorm
84 New Member
Can anyone help ?? :(
Sep 30 '07 #6
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

sSQL = "Select * from Feed Where Feed_ID =" & txthopper(2).Text

Check field name :
Feed_ID

txthopper(2) -- value of this text box..

Regards
Veena
Sep 30 '07 #7
metalheadstorm
84 New Member
nope same prob
all i get is

Expand|Select|Wrap|Line Numbers
  1. run-time error 424
  2. Object required
then under the yellow error text:

dbOpenDynaset =2
sSQL = "Select * from Feed Where Feed_ID =10008"
Oct 5 '07 #8

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

Similar topics

0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
21
by: Dan | last post by:
Hi, just ran into my first instance of a backend Access97 database not compacting. I'm getting the "MSACCESS.EXE has generated errors.." message on compact. I've narrowed it down to the largest...
3
by: AW | last post by:
Hi all, I have a form (named Offices) with a subform (named Occupants) that connect with the Master/Child Field "office number". I have a combo box that allows a user to pull up a particular...
9
by: Christopher Koh | last post by:
I will make a form which will search the database (just like google interface) that will look/match for the exact name in the records of a given fieldname. Any suggestions on how to make the code?
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
4
by: rszebras | last post by:
I inherited a database (as a novice at Access) and need to modify it to make it more efficient, i.e., the assignment form needs to autopopulate with the client's name, address, phone number, etc.,...
10
by: jonathan184 | last post by:
Hi I tried getting this to work through dreamweaver but it did not. So i found a n example on the internet , i followed everything exactly the search script does not work. Could somebody help me...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.