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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

guys, i have a form with txtboxes o 1

Status
Not open for further replies.

knaya

MIS
Dec 4, 2003
51
US
guys, i have a form with txtboxes on it and on the click of a button, i'm trying to get values from the txtboxes to post to a new table.. The table is called dunptable(which has 3 fields namely productid, productname and cost) and the txtboxes on the form (called sell) are text4, prod and sale.. The code i have is:

Dim solditems As Recordset
Dim newbob As Database
Set solditems = newbob.OpenRecordset("dumptable")
solditems.AddNew
solditems(ProductId) = Forms![frmsellitem]!Text4
solditems(ProductName) = Forms![frmsellitem]!prod
solditems(Price) = Forms![frmsellitem]!Sale
solditems.Update

When i click the button, this comes up "User defined type not defined" and the newbob as datbase is highlighted:-( .. what am i doing wrong? Any info will be so appreciated..Thankssssssss
 
Hi!

This looks like DAO code without having the Microsoft DAO 3.N Object Library checked (in any module, select Tools | References and select/check the mentioned library, N=numeric, probably 6)

Then perhaps some more (note explicit declaration (dao) of the database and recordst:

[tt]Dim solditems As dao.Recordset
Dim newbob As dao.Database
set newbob = currentdb()
Set solditems = newbob.OpenRecordset("dumptable")
solditems.AddNew
solditems!ProductId = Me!Text4
solditems!ProductName = Me!prod
solditems!Price = Me!Sale
solditems.Update
solditems.close
set solditems=nothing
set newbob=nothing[/tt]

Note, in your text, you say field name "cost" in the code you've used "Price". You also say form name "sell" and refer to "frmsellitem". Might check that out to;-) You say you call this code from the frmSellitem/sell form, then as I've done in the code, the form references might be substituted with the keyword "Me".

HTH Roy-Vidar
 
Roy-Vidarrrr, you are zeeeeee greatest, i am always getting results from your inputs.. Thanks so muchhh.. i have another problem though, the button is working finee and the dumptable is updating when the button is pressed but i have a subform(a continuos form..sourceobject = dumptable)when i click on the update button, the contents update in the table but not in the form..if i close the fom and open it back up, the subform is updated also, how can i get the subform to update without having to close it and open it back up... Thank you Access Grandmaster :)
 
You are far too kind, and I'm definately not worthy of such description!

At the end of the code, a requery might come in handy:

You might try something like this:
[tt]me!frmNameOfSubForm.Form.Requery[/tt]

or a more complete reference
[tt]Forms!frmNameOfMainForm!frmNameOfSubForm.Form.Requery[/tt]

Substitute formnames...

HTH Roy-Vidar
 
Roy-Vidar,
This is the code i put in:
Forms!frmsell!frmupdate.Form.Requery
the form is called sell and the subform is called update but when i click the button, it says "microsoft Access cant find the form "frmsell" referred to in macro expression".. i now changed the "frmsell to just "sell" and another error message just comes up.. i'm i typing this the wrong way.. Thanks a lot.
 
Hi!

You must use the names of the forms (as vieved in the forms tab in the database window). If the names are "sell" and "update" (note1) then use them. If they are "frmSell" and "frmUpdate" then...

Note1 - the name "update" must be avoided, cause it's a reserved word in Access/VBA ("frmUpdate" would be a better name). I (and, it seems a lot of the others on this site) use the naming convention of always prefixing forms frm..., all textcontrols on a form/report txt...

HTH Roy-Vidar
 
Roy-Vidar,
me again :), i have changed the names and now using:
Forms!sell!checkout.Form.Requery where sell is the main form and checkout is the subform that i would like to automatically update itself based on new records entered into the table its control source is set to but then i get this error message when i click the update button:
"microsoft cant find the field "checkout" referred to in your expression" ... what can i do, change, delete etc??? Thanks a lot..

 
Hi again!

I think that renaming the form (from update to checkout) in the database window is step 1, step 2 would be to rename also the "sub/main" connection.

In design view, keep the properties tab open at the data tab. First select the main form, then click once on the subform. Rename there also the name from update to checkout.

Should of course have remembered that too when "ordering" you to rename:-(

HTH Roy-Vidar
 
Roy-Vidar,
you have no idea how happy i am right now, i'm like screaming and jumping cause after hours and hours of trying to get this to work, its finally working (thanks to you)...THANK YOU SO MUCHHHHHHH..for not only helping me figure this out but also for very detailed.. i'm sure i'll have more questions posted real soon and even if i dont get the answers, you have definately made my day.. Thanks again
 
Thank you thank you thank you, both for the very kind words, and the star! Happy to assist!

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top