Avatar of Nancy Therrien
Nancy Therrien
Flag for Canada asked on

MSAccess Form VBA saving

Good morning,
I have a problem this morning...
I have a form in which I can enter up to 50 numbers and when I click on print, it will print my report as I want to.  This work great.  The problem is :  is there a way that the 50 numbers I have entered will be memorise (saved) when I finished printing, for the next time I will need to print the report.  I want to be able to change some number, erase some and keep some.........................

Can you Expert help me please.  Thanks
form.jpg
code-vba.jpg
Microsoft AccessProgrammingVBA

Avatar of undefined
Last Comment
Nancy Therrien

8/22/2022 - Mon
ste5an

It's Access.. Store those numbers in a table?!
Nancy Therrien

ASKER
Hello Ste5an,


I have tought a creating a table for that but I don't know how to process from VBA................
ste5an

Create a table first. then bind the form to that table. use an continuous form. Then you don't need so much controls.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Jeffrey Coachman

I would ask why those number were not stored in a table all along.
(in the same table that stores the other form fields)
This would help if:
You need a history of those numbers
You need to see when they were entered? (set a default value of Today's date and time)

So can you could tell us why these numbers are being entered into an "unbound" control?

Just curious...

JeffCoachman
Nancy Therrien

ASKER
Hello Jeffrey,  Each month we have a list of job order in a excel form that we need to type in that form for it to give us the report we want.  We were not keeping it cause we did'nt need it until now.

Now I have to keep it and be able to delete and modify it on request and print the same report.

I have create a table to put them in but I have to figure out how to link it to my form......

Thanks
PatHartman

Your original design was unnormalized.  Because it was flat like a spreadsheet, and had data that repeated in columns rather than rows, you needed to decide at design time the maximum you would allow.  Now that you have your data in rows (one row per job), you can technically support an infinite number of jobs and no change would be required if all of a sudden you needed to report on 100 jobs.  That is the beauty of normalization.  Rows are free, columns are expensive.

You need to import the data from the spreadsheet or link to the spreadsheet.  I prefer linking since this isn't something that you actually need to keep.  Each time you run the reports, you will be using a new version of the list.  The code you have  loops through the controls on the form.  The new code will open a recordset and loop through the rows in the recordset.
Dim db as DAO.Database
Dim rs as DAO.Recordset
Dim td as DAO.Tabledef

Set db = CurrentDB()
Set td = db.Tabledefs!yourtablname
Set rs = td.OpenRecordset

Do Until rs.EOF = True
  .... your print report code
    rs.MoveNext
Loop

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Nancy Therrien

ASKER
Hello all,
Thanks for all your answer.  I have create my table and yes it is a better idea.  Thanks
Mr PatHartman I will try your code for my report.  

Thanks again
Nancy Therrien

ASKER
Hello,  It is giving me a non definite something error.........
Is the way I have the date to be a filter will work ?

thanks
Nancy Therrien

ASKER
Ok I have figure out the non definite error , the DAO was not include.

Now it seems to print something but very too much.

Private Sub cmdPrint_Click()

       
Dim sfilter As String
Dim stDocName As String
           
                 
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim td As DAO.Tabledef

Set db = CurrentDb()
Set td = db.Tabledefs!tbl_NoJobRequis
Set rs = td.OpenRecordset

Do Until rs.EOF = True
         
 'sfilter = "[NO_JOB]=" & ctl & " AND [DATE]>=#" & Format(DateValue(Me.txtDate), "yyyy\/mm\/dd") & "#"             this seems not to work, giving a error

           sfilter = "[DATE]>=#" & Format(DateValue(Me.txtDate), "yyyy\/mm\/dd") & "#"
            stDocName = "rpt_Temps Job Particulier sans critere"
            DoCmd.OpenReport stDocName, , , sfilter           'not working cause printing a way too much pages.........
    rs.MoveNext
Loop

         
 '   DoCmd.Close
 '   DoCmd.OpenForm "menu"
End Sub
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
PatHartman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Nancy Therrien

ASKER
Hello PatHartman,

Thanks you for your help.  It is working great now.

Here is my code :
Private Sub cmdPrint_Click()

       
Dim sfilter As String
Dim stDocName As String
Dim No_Job As String
           
           
                 
       
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim td As DAO.Tabledef

Set db = CurrentDb()
Set td = db.Tabledefs!tbl_NoJobRequis
Set rs = td.OpenRecordset

Do Until rs.EOF = True
           With rs
            No_Job = !No_Job
            sfilter = "[No_Job]=" & !No_Job & " AND [DATE]>=#" & Format(DateValue(Me.txtDate), "yyyy\/mm\/dd") & "#"
            stDocName = "rpt_Temps Job Particulier sans critere"
            DoCmd.OpenReport stDocName, acViewNormal, , sfilter
           End With
    rs.MoveNext
Loop

         
 '   DoCmd.Close
 '   DoCmd.OpenForm "menu"
End Sub
Nancy Therrien

ASKER
thanks very much