A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Cannot add a new item



 
 
Thread Tools Display Modes
  #1  
Old December 21st, 2006, 02:45 PM posted to microsoft.public.access.forms
AC
external usenet poster
 
Posts: 4
Default Cannot add a new item

Hello,
I have a form that displays records from a table called tbl_item. I
have added some code, shown below, to the Form_Current procedure to
refresh certain fields on the form based on a value selected from a
combo box. It appears that this code below prevents me from adding a
new record. When I select the 'new record' button at the bottom of the
form (that standard access navigation button), it just recalculates and
then goes to the first record.

Could somebody please explain why this is happening and what I need to
change?

Here is the code:
Private Sub Form_Current()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Item_Number] = '" & Me![txt_ItemNo] & "'"
Me.Bookmark = rs.Bookmark
Me.cbo_packaging.Requery
Me.txt_FtyNo.Locked = True

Me.txt_FtyNo = ""
Me.txt_pack_category = ""
Me.txt_port = ""
Me.txt_FirstCost = ""
Me.txt_ItemItemL = ""
[...]
End Sub


Also, I tried to add a command button to add a new record, but that
generates another error message, saying 'You can't go to the specified
record.'

Any help/solutions are greatly appreciated.

Thanks in advance.
Regards,
A. Crawford

  #2  
Old December 21st, 2006, 02:58 PM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Cannot add a new item

You cannot use that code without tying yourself in knots.

The current event fires whenever the form moves to a different record. In
the current event, you are finding another record, and moving to that one
(by setting the form's bookmark property.) Since you moved record, Access
will fire the Current event of the form. So, your code fires again, which
moves record, which fires Form_Current, which ...

Assuming that the code actually does work, do you see the problem here?

It makes no sense to move record in Form_Current.

Similarly it makes no sense to change the value of any bound controls just
because you visited a record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"AC" wrote in message
ps.com...
Hello,
I have a form that displays records from a table called tbl_item. I
have added some code, shown below, to the Form_Current procedure to
refresh certain fields on the form based on a value selected from a
combo box. It appears that this code below prevents me from adding a
new record. When I select the 'new record' button at the bottom of the
form (that standard access navigation button), it just recalculates and
then goes to the first record.

Could somebody please explain why this is happening and what I need to
change?

Here is the code:
Private Sub Form_Current()
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Item_Number] = '" & Me![txt_ItemNo] & "'"
Me.Bookmark = rs.Bookmark
Me.cbo_packaging.Requery
Me.txt_FtyNo.Locked = True

Me.txt_FtyNo = ""
Me.txt_pack_category = ""
Me.txt_port = ""
Me.txt_FirstCost = ""
Me.txt_ItemItemL = ""
[...]
End Sub


Also, I tried to add a command button to add a new record, but that
generates another error message, saying 'You can't go to the specified
record.'

Any help/solutions are greatly appreciated.

Thanks in advance.
Regards,
A. Crawford



  #3  
Old December 21st, 2006, 03:30 PM posted to microsoft.public.access.forms
missinglinq via AccessMonster.com
external usenet poster
 
Posts: 545
Default Cannot add a new item

Kinda like the legendary bird that flies around in ever tightening circle
until he finally flies up his own a$$!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:00 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.