Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A simple code that only work 1/2 the time

Status
Not open for further replies.

haerion

IS-IT--Management
Sep 13, 2006
130
0
0
US
Hi all,

I am having some weird problem here. i got the following code, but for some reason, sometime it doesn't work and sometime it does. I was unable to find a pathern as to why it doesn't work sometime.

Here is the code:

Code:
Private Sub Itemno_Change()
On Error GoTo err_itemnoChange

Me.Desc1 = Me.Itemno.Column(1)
Me.Desc2 = Me.Itemno.Column(2)
Me.Eight = Me.Itemno.Column(5)
Me.Cat = Me.Itemno.Column(3)
Me.Avail = Me.Itemno.Column(4)

err_itemnoChange:
Exit Sub
End Sub

This code is on the onchange event of the listbox, which is in a subform.

Any of you got an idea to fix this?
 
haerion said:
Any of you got an idea to fix this?
Yes, actually display whatever error is occurring in your error handler.

Code:
err_itemnoChange:
[COLOR=blue]MsgBox "Error #" & Err.Number & ": " & Err.Description
[/color]
Exit Sub

Joe Schwarz
Custom Software Developer
 
How are ya haerion . . .

Curious this! [surprise]

[blue]Why are you using the change event?[/blue] ... the logic of your code doesn't appear to fit its use!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 

I agree with Aceman1, move your code to Itemno_AfterUpdate().

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Here is the error when it doesn't work:


Error # -2147352567:The object doesn't contain the automation object 'me'. (Possible it is not exaclty the same sentence since I had to translate it in english from french :p)

I am using this code so that when I select an item on the listbox, it automatically change the column 2-5 to the data corresponding.

Im good TheAceMan, hope you doing well too :)

And yes this is very weird :p

I change it to the afterupdate one, still getting the same error, but true, this one is better than change :p my mistake :)

Thanks all for your help
 
haerion . . .

Be Aware: column index in a listbox or combobox starts at zero! Perhaps what you really want is columns 0 thru 4.

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
No, column 0 is the item, seriously, the information is taken from the right place. It's just that something everything fill out perfectly and some other i got the error... that's just plain weird!!!

 
Is it neccasary to use "me."? I would think the results are the same if using "Desc1 = Itemno.Column(1)".

Could the real error be a type mismatch?
 
I removed all the "me." and still got the same error :(
 
Have you tried using a combobox instead of a listbox?
 
I can't use a combobox, since it is a subform that is used in a datasheet view
 
Try substituting the complete name for Me.
Forms!frmName.cboName


Randy
 
haerion . . .

At this point I'd [blue]delete then reconstitute[/blue] the listbox ...

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I tried to delete/reconstitute the listbox, but i still got the same problem :(

The main form is "Entry"
The subform is "ItemCustWant1_subform"

The listbox lboItemno is on the subform
The Event is on the afterupdate of the lboItemno

The subform is in datasheet view.

If you need any more info to help you, just ask :)

Thanks
 
Try making it Form view in contiunous forms instead. I think your controls are limited in datasheet view. The listbox then becomes the value list you set up for the field in your table. You can mimic the datasheet view by adding a form header, and then running a continous form view in the detail. Then you retain all the benefits of your controls.
 
Ok, I tried in continous form view, and the result is the same, sometime work, sometime don't :(
 
My main form (Entry) is based on the query Main Table which is as follow:
Code:
SELECT [Table Header].IDTag, [Table Header].Date, [Table Header].Status, [Table Header].PO, [Table Header].ShipVia, [Table Header].ShipDate, [Table Header].FollowUp, [Table Header].SO, [Table Header].Acronym, [Table Header].CustName, [Table Header].Addr1, [Table Header].Addr2, [Table Header].Addr3, [Table Header].Postal, [Table Header].OnHold, [Table Header].SYTD, [Table Header].CieTel, [Table Header].CieFax, [Table Header].Level, [Table Header].TraneModel, [Table Header].TraneSN, [Table Header].Notes, [Table Header].Clerk, [Table Header].Contact, [Table Header].ContactEmail, [Table Header].ContactTel, [Table Header].ContactFax, Clerk.Name, [Table Header].TAF, [Table Header].Installation, [Table Header].Tech, [Table Header].TranePO, [Table Header].TrsfNo, Clerk.Store, [Table Header].TrsfNo2, Clerk.VersysUser, Clerk.VersysPass, Clerk.ELUser, Clerk.ELPass, Clerk.CitrixUser, Clerk.CitrixPass
FROM Clerk RIGHT JOIN [Table Header] ON Clerk.Clerk = [Table Header].Clerk
ORDER BY [Table Header].IDTag;

Then, there is the subform (ItemCustWant1_subform) based on qryItemCustWant which is as follow:
Code:
SELECT ItemCustWant.IDTag, ItemCustWant.Itemno, ItemCustWant.Desc1, ItemCustWant.Desc2, ItemCustWant.Cat, ItemCustWant.Avail, ItemCustWant.[$Eight], ItemCustWant.Price, ItemCustWant.Qty, [Qty]*[Price] AS Total, ItemCustWant.Check
FROM ItemCustWant
WHERE (((ItemCustWant.IDTag)=[forms]![entry]![txtIDtag]));

And finally there is a one-to-many relation between "Table Header" and "ItemCustWant" with the IDTag.

Got I can't find any reason as for why it doesn't work all the time... :(
 
I just realized that it is always working on the same item#. It is not that sometime it work and sometime it doesn't, but more like some item# work and other doesn't.

And moreover, I tried to add the following at the end of the code:
msgbox desc2

This one always work on all item#, but seem like the problem lies in the copy to txtdesc2. Gonna go crazy soon about all this stuff :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top