How to roll month and year in a txt box from record to record

  • Thread starter Balmora via AccessMonster.com
  • Start date
B

Balmora via AccessMonster.com

Well, nothing works. i will try too explan it ai simple as i can lets say i
have one table named MyTable and in my table i have only mmmmyyyyID i want to
call it that way because i want monthe in full and year in 4 digits so it
looks like May 2008 lets say i guess i can always right the first id by hand
so it can start by their and i was thinking that maybe i can put the vba code
in the next record command button that i coded this way

Private Sub cmdNewRec_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End Sub

as you can see i put Me.AllowAdditions = True because this is the only button
that can add a new record :) so to start off from their i was wondering if i
should create a table called month and have like Id and Month and insert all
12 month of the year and then some how have the code in the cmdNewRec button
go thow all the 12 records to display the month and when it gets to the end
it would increment the year by one and then start over. maby use some format()

and some Dlookup in the code i realy dont know but this is how i see it.

do you think its possible. to be used as a primary key i know its not the
best way to go but this is what i need. i see this as a realy good learning
experience. thank you in advance for all your help. :)

oh!
i thought this over and i guess i can keep a autonumber for the primery key i
realy just need the month and year to increment automaticaly so a month is
never skiped because i then make a time stamp of it for some filtering. :) i
know im making some happy by not using it for a primery key :) hope to here
from you all soon :)
 
D

Dave C

I'm not sure I follow everything you wrote, but it sounds like you're trying
to put in a button that will create a new record with the next available
month. If so, here's a solution...

private sub AddRecord_click()
docmd.setwarning false
docmd.runsql "INSERT INTO tblMyTableName (dteMonth) VALUES (" _
& format(dateadd("m",1,nz(dmax("dteMonth","tblMyTableName"),now))) _
& ")"
docmd.setwarning true
me.requery
me.recordset.movelast
end sub
 
B

Balmora via AccessMonster.com

Well i love your idea but you will have to explane a bit more pls, i changed
to budget for the tbl name and dteMonth to monthandyear for the field that
need month to roll is that good ? and when i try it, it gives me an error on
the ling that has docmd.setwarning false

Dave said:
I'm not sure I follow everything you wrote, but it sounds like you're trying
to put in a button that will create a new record with the next available
month. If so, here's a solution...

private sub AddRecord_click()
docmd.setwarning false
docmd.runsql "INSERT INTO tblMyTableName (dteMonth) VALUES (" _
& format(dateadd("m",1,nz(dmax("dteMonth","tblMyTableName"),now))) _
& ")"
docmd.setwarning true
me.requery
me.recordset.movelast
end sub

Well, nothing works. i will try too explan it ai simple as i can lets say i
have one table named MyTable and in my table i have only mmmmyyyyID i want to
[quoted text clipped - 27 lines]
know im making some happy by not using it for a primery key :) hope to here
from you all soon :)
 
J

John W. Vinson

Well i love your idea but you will have to explane a bit more pls, i changed
to budget for the tbl name and dteMonth to monthandyear for the field that
need month to roll is that good ? and when i try it, it gives me an error on
the ling that has docmd.setwarning false

Try Docmd.SetWarnings False (and follow it up with a DoCmd.SetWarnings True).

Just missing the s at the end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top