ms-access


How can I use the database commands 'Seek' and results 'NoMatch'?


Here's my problem:
Let's say I have these tables:
table1
1 - "a"
2 - "b"
table2
1 -
2 -
3 -
Now, I'm using the following code to compare the tables:
table2.MoveFirst
Do While Not table2.EOF
table1.Seek "=", table2!field2
If table1.NoMatch Then
go do a lot of things to find that information
Else
table2.Edit
table2!Field2 = table1!field2
table2.update
End If
table2.MoveNext
Loop
But the line
table2!Field2 = table1!field2
Is not working so well. I'm pretty sure I'm doing something wrong here, but I'm having problems finding a solution. I'm not even sure what I should google...
EDIT: Field 2 is indexed in table 1, so the 'seek' works.
A few notes.
Let us say you want all the records from Table2 where there is no match on a field called Field1:
sSQL = "SELECT Field1, FieldX FROM Table2 " _
& "LEFT JOIN Table1 " _
& "ON Table2.Field1 = Table1.Field1 " _
& "WHERE Table1.Field1 Is Null"
You could, of course, build the query in the query design window and fiddle around until is is just what you want, then switch to SQL view to get the right (ish) SQL string.
Dim rs As DAO.Recordset
Set rs = CurrentDB.Openrecordset(sSQL)
''table2.MoveFirst
Do While Not rs.EOF ''table2.EOF
''You do not need no match, all these records are missing a match
'' table1.Seek "=", table2!field2
'' If table1.NoMatch Then
go do a lot of things to find that information
rs.MoveNext
Loop
''This can all be done with one update query
'' Else
'' table2.Edit
'' table2!Field2 = table1!field2
'' table2.update
'' End If
'' table2.MoveNext
'' Loop
sSQL = "UPDATE Table2 " _
& "INNER JOIN Table1 " _
& "SET table2.Field2 = table1.field2 "
CurrentDB.Execute sSQL dbFailOnerror
Please treat the above as notes, not finished code.
But the line table2!Field2 = table1!field2 Is not working so well
...is not a good description of what goes wrong.
Does the code stop/crash at this line?
Does it run without errors, but do nothing / something else than you expected?
I suppose that you're using DAO Recordsets.
It's hard to give advice without more information, but I'll give it a try:
Is table2 completely empty? Your description looks like this:
table2
1 -
2 -
3 -
If yes, the whole loop is probably never executed at all.
Can the Recordset table2 be updated?
Not all types of Recordsets support this, it depends on how you create it. See MSDN: Recordset Object (DAO), there is a list of Recordset types at the beginning.
If it's not updateable, you should get an error when you call .Update.
If you're using DAO recordsets (as suggested by Christian) you can change the line
table2!Field2 = table1!field2
to
table2.Fields("Field2").value = table1.Fields("field2").value
I'm presuming both Field2's are of Text data type.

Related Links

MS Access: Set focus on a Radio Button
Access 2010 dislikes my .mdb file
Ms access query for dont show blank filed
MS Access Update Query
Time picker access 2007
How to make Totals in access 2007
Font size mismatched between embedded Word object and text boxes
LZMA Compression For VB6/VBA?
Access: How to automatically create a record in related tables
Drop down box in Access used to let me enter data to pick it faster but now it doesnt?
Microsoft Access version rules when using TFS Source Control
Using VBA from Access 2007 to search in AutoCAD (dwg) files
Access - VBA Sub not called [closed]
Recover VBA Code from Access DB File
view data of recordset in immediate window
Encrypt PDFs In Access 2000

Categories

HOME
isabelle
gremlin
octobercms
google-docs
infragistics
rdf
win32gui
umd
pivotal-cloud-foundry
datastax-java-driver
convolution
communication
vault
izpack
qt-creator
etl
messages
netflix
database-replication
beyondcompare
sylius
zurb-foundation-6
hammerspoon
uninstall
compatibility
google-cloud-nl
procdump
srcset
ecto
preg-match-all
framemaker
vsts-build-task
protovis
windows-dev-center
gammu
ghost4j
cloud-code
devextreme
hot-module-replacement
libraries
greenrobot-eventbus
cookiecutter-django
trim
turbogears
segment
sas-jmp
angular2-meteor
menuitem
flickr-api
domain-model
dotnetzip
mplayer
colorama
sqlclient
snmptrapd
sybase-asa
pdfclown
mako
synchronous
parallel-data-warehouse
xcb
wdf
py2app
google-web-starter-kit
paypal-express
lua-5.1
pickadate
hexdump
jfugue
jms2
cartesian-product
marching-cubes
tarjans-algorithm
muse
p2
skos
lustre
umbraco6
asp.net-dynamic-data
id3v2
googlemock
flask-cors
xojo
responsive-slides
openexr
article
contenttype
jubula
expected-exception
concurrent-collections
page-layout
ora-00911
cos
gridcontrol
rabl
django-nonrel
jelly
itmstransporter
simba
chuck
cisco-jtapi
broken-links
dsn
cascalog
twrequest
jquery-ui-layout
assembly-loading
custom-backend
pydot
yetanotherforum
calling-convention
gamequery
dmx512
routedevent
dbal
user-friendly
substrings
ti-dsp
mtj
.net-1.0

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App