473,504 Members | 13,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using VB to navigate from one record to another

Hi. I have a simple MS Access 2000 form in which I enter some customer
data. When the address field is entered I need to see if a duplicate
record exists. I need to know this *right away* before the remaining
fields are filled out, so I'm trying to call a function on the
Address_LostFocus() event which will do the lookup. If a match is
found, it should prompt the user to either continue, or navigate to
the existing record. This is where I'm stuck (the navigation). I've
tried a bunch of things, but do not have the Access experience to
effectively solve this problem. Please help!

This is what I have so far:

Dim strSQL As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
strSQL = "SELECT * FROM customers WHERE address ='" & Address.Text &
"'"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)

If rst.RecordCount > 0 Then
If MsgBox("A record exists with a matching address. Click OK
to edit the existing record.", vbOKCancel) = 1 Then
'navigate to existing record
End If
Else
MsgBox ("Keep Going...")
End If
Nov 12 '05 #1
1 5282
Assuming that your form is bound to "customers" then you could use the
form.recordsetclone rather than your recordset. Something like this
(untested!)

Dim rst As DAO.Recordset

Set rst = Me.RecordsetClone

With rst
.FindFirst "address= '" & Me.address & "'"
If Not .NoMatch Then
if msgbox ..... then
Me.Bookmark = .Bookmark
End if
End If
.Close
End With
'End of code

Note that this code will still create a new record even if it moves to the
existing address record. You may want to include a Me.Undo to prevent this
happening. You may also be better off using the BeforeUpdate event rather
than the LostFocus event as then you can cancel the event before moving to
an existing record.

In your code you have used Address.Text. I don't think this will work in the
LostFocus event as the text property is only available when the control is
being edited. It is usually used in the Change event - this would be another
option for your code (when you MUST use the .text property), and would mean
that the address is checked every time the user types a new character into
the address field. If you choose to use the change event it may be better to
make rst a module level variable and use the control's enter event to set
rst, and another event to close it. That way you're not creating and
destroying the rst object every time a character is typed in.

Andrew

"Joe Bond" <j0******@hotmail.com> wrote in message
news:cb*************************@posting.google.co m...
Hi. I have a simple MS Access 2000 form in which I enter some customer
data. When the address field is entered I need to see if a duplicate
record exists. I need to know this *right away* before the remaining
fields are filled out, so I'm trying to call a function on the
Address_LostFocus() event which will do the lookup. If a match is
found, it should prompt the user to either continue, or navigate to
the existing record. This is where I'm stuck (the navigation). I've
tried a bunch of things, but do not have the Access experience to
effectively solve this problem. Please help!

This is what I have so far:

Dim strSQL As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
strSQL = "SELECT * FROM customers WHERE address ='" & Address.Text &
"'"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)

If rst.RecordCount > 0 Then
If MsgBox("A record exists with a matching address. Click OK
to edit the existing record.", vbOKCancel) = 1 Then
'navigate to existing record
End If
Else
MsgBox ("Keep Going...")
End If

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2972
by: Philip Mette | last post by:
I have been searching many postings and I cant seem to find anyone that has this answer so I decided to post. I am using SQL (Transact-SQL).If I have 2 tables with columns...
1
1693
by: Dreamerw7 | last post by:
Hi, I know this is probably a dumb question, but here goes: I have 3 tables: REGION REG_ID REGION
1
2008
by: Bo Long | last post by:
I believe the following a valid SQL statement, but MS Access returns with an error "Operation must be an updateable query". Any suggestions would be greatly appreciated! UPDATE FERCPTILoad AS...
1
2418
by: ILCSP | last post by:
Hello, I'm trying to accomplish 3 things with one stored procedure. I'm trying to search for a record in table X, use the outcome of that search to insert another record in table Y and then exec...
2
1727
by: Maximus | last post by:
I need some help. I have an .asp page that interfaces with an Access table (wjs_SuperInput). The .asp page looks to the table and pulls a recordset based on a job number, 12345, and a weekending...
3
2713
MattFitzgerald
by: MattFitzgerald | last post by:
My Forms & Tables:- Main form is Frm_LE_List (contains Customer Details) Stored in Tbl_LE_List Which contains subform Frm_VOL_References (Contains Orders known as VOL's) Stored in...
2
8450
by: SJ1000 | last post by:
Hi, I think I have a simple question that I just can't figure out. I want to have a command button on a form (via a macro) run a query to append the data on that form to another table.I want it to...
0
1245
by: emrodge | last post by:
Hi, Any help appreciated on this one. I've set up a simple database with 4 tables & 3 forms. The tables link together on a field called "client id" which is the ID in a table called "Clients". I...
2
2448
by: jhoelter | last post by:
Hi, First of all, I thank you for reading the following post and taking a little bit of your time helping me figuring this out. I first tryed to explain my exact case, but it is to hard. Let me...
0
7098
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...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
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
4698
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
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.