473,378 Members | 1,449 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,378 software developers and data experts.

Set focus in a recordset?

Hi! This is a problem I have: I have an Orderform and an OrderDetails
form. I will have the user register a sparepartnr in the OrderDetails
form, but only if that number doesn't exist already. If it exist I'll
have a messagebox popUp and when he clicks ok I'll set the focus on
the actual field in the OrderDetails form, which is the fifth field on
the line. But where do I go wrong? It all works fine, except that I
can't seem to set the focus when returning from the messagebox!

Private Sub SparePartnr_AfterUpdate()
On Error GoTo Err_NrAU

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset(
"SELECT DISTINCT OrderID,DetailID,ItemID,SparePartnr
FROM tblDetail
WHERE SparePartnr = '" & Me!SparePartnr & "'", dbOpenDynaset)

If rs.EOF Then
MsgBox "SparePartnr registered!", vbInformation + vbOKOnly,
"THANKS!"
Else
DoCmd.Beep
MsgBox "A sparepart with identical nr exists!" & Chr(13) _
& "Itemnr: " & rs!ItemID & Chr(13) _
& "Linenr: " & rs!DetailID & Chr(13) _
& "SparePartnr: " & rs!SparePartnr, vbCritical + vbOKOnly,
"¡¡¡ALERT!!!"

//This must surely be wrong?:
With Me
.SparePartnr.SetFocus
End With

End If

rs.Close
db.Close

Exit_NrAU:
Exit Sub

Err_NrAU:
MsgBox Err.Source & Chr(13) _
& Err.Number & " " & "SparePart/SparePartnrAU" & Chr(13) _
& Err.Description, vbCritical + vbOKOnly
Resume Exit_NrAU
End Sub
Nov 13 '05 #1
2 3805
Do your test in the beforeupdate event not the AfterUpdate event.

The BeforeUpdate event has a Cancel parameter if you set this Cancel
parameter to True it will cancel the event and keep focus in the SparePartnr
control.

So put your code in the BeforeUpdate event and make the modification shown.
On Error GoTo Err_NrAU

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset(
"SELECT DISTINCT OrderID,DetailID,ItemID,SparePartnr
FROM tblDetail
WHERE SparePartnr = '" & Me!SparePartnr & "'", dbOpenDynaset)

If rs.EOF Then
MsgBox "SparePartnr registered!", vbInformation + vbOKOnly,
"THANKS!"
Else
DoCmd.Beep
MsgBox "A sparepart with identical nr exists!" & Chr(13) _
& "Itemnr: " & rs!ItemID & Chr(13) _
& "Linenr: " & rs!DetailID & Chr(13) _
& "SparePartnr: " & rs!SparePartnr, vbCritical + vbOKOnly,
"¡¡¡ALERT!!!"

' ***********************
Cancel = True
' ***********************

rs.Close
db.Close

Exit_NrAU:
Exit Sub

Err_NrAU:
MsgBox Err.Source & Chr(13) _
& Err.Number & " " & "SparePart/SparePartnrAU" & Chr(13) _
& Err.Description, vbCritical + vbOKOnly
Resume Exit_NrAU
--
Terry Kreft
MVP Microsoft Access
"Geir Baardsen" <ge***********@hotmail.com> wrote in message
news:35*************************@posting.google.co m...
Hi! This is a problem I have: I have an Orderform and an OrderDetails
form. I will have the user register a sparepartnr in the OrderDetails
form, but only if that number doesn't exist already. If it exist I'll
have a messagebox popUp and when he clicks ok I'll set the focus on
the actual field in the OrderDetails form, which is the fifth field on
the line. But where do I go wrong? It all works fine, except that I
can't seem to set the focus when returning from the messagebox!

Private Sub SparePartnr_AfterUpdate()
On Error GoTo Err_NrAU

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset(
"SELECT DISTINCT OrderID,DetailID,ItemID,SparePartnr
FROM tblDetail
WHERE SparePartnr = '" & Me!SparePartnr & "'", dbOpenDynaset)

If rs.EOF Then
MsgBox "SparePartnr registered!", vbInformation + vbOKOnly,
"THANKS!"
Else
DoCmd.Beep
MsgBox "A sparepart with identical nr exists!" & Chr(13) _
& "Itemnr: " & rs!ItemID & Chr(13) _
& "Linenr: " & rs!DetailID & Chr(13) _
& "SparePartnr: " & rs!SparePartnr, vbCritical + vbOKOnly,
"¡¡¡ALERT!!!"

//This must surely be wrong?:
>With Me
>.SparePartnr.SetFocus
> End With

End If

rs.Close
db.Close

Exit_NrAU:
Exit Sub

Err_NrAU:
MsgBox Err.Source & Chr(13) _
& Err.Number & " " & "SparePart/SparePartnrAU" & Chr(13) _
& Err.Description, vbCritical + vbOKOnly
Resume Exit_NrAU
End Sub

Nov 13 '05 #2
"Terry Kreft" <te*********@mps.co.uk> wrote in message news:<Go********************@karoo.co.uk>...
Do your test in the beforeupdate event not the AfterUpdate event.

The BeforeUpdate event has a Cancel parameter if you set this Cancel
parameter to True it will cancel the event and keep focus in the SparePartnr
control.

So put your code in the BeforeUpdate event and make the modification shown.


' ***********************
Cancel = True
' ***********************

Wov, where do U get the magic?

Sometimes I feel like a motherless child...

Thanks! :-)
Me.Name = Me.NeedStudyMore.Value = True
Nov 13 '05 #3

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

Similar topics

4
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use...
2
by: Drew | last post by:
I have a form which has 1 textbox in it. When the user enters a number, and tabs, it submits the form and the textbox disappears and the name of the person that the ID corresponds to is displayed...
3
by: David Altemir | last post by:
I have a button on "Form A" in the right margin of every record in my recordset. When you click on a button, a dialog box ("Form B") pops up that gives more details about that particular record. ...
2
by: S P Arif Sahari Wibowo | last post by:
Hi! Do you know how to put a form's Access-Visual-Basic-code that will force the form to be inserted, while the user has not type anything in the form, without changing focus, selection, etc.? ...
5
by: Prakash | last post by:
I have a continuous form in which I don't want to allow more than 255 rows. There is a field called sub_tran_no which is of the type "BYTE" & hence the restriction. My Problem: -----------...
8
by: Susan Bricker | last post by:
Hi. I am opening a form (frmUserSettings) just before (or so I thought) the Main Menu form (frmMainMenu) is opening but it's not getting the focus. It gets "painted" and then the Main Menu gets...
55
by: salad | last post by:
I have contained in a listbox the Window's caption, the class name for the window, and the hWND of the window. Is there a way, using the data from above, to activate/set focus to that window?
1
by: Reginald Bal | last post by:
Main Form/SubForm When I requery or recalc my parent form after I updated a record in my subform, I lose the focus of that particular record in my subform. Instead, the first record is selected....
1
by: kaeldowdy | last post by:
This one is stumping me! I have a Form/Subform arrangement. The main form is set as a Single Form and the sub form is set as Continuous Forms. On the Form_AfterUpdate event of the subform, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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...

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.