Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Syntax to divide form values and update table as percentage with 2 decimals; close form and open another form

Posted on 2013-12-12
4
Medium Priority
?
744 Views
Last Modified: 2013-12-12
The following is the VBA code I wrote to update a table from a form.  I have two questions.

First I want to divide the form entries:

Me.txtXM / Me.txtTM and update the table field XMPERC as a Percentage with 2 decimal places.

Second I need to close the open form frmSR1 and reopen frmEvalMenu.

What is the syntax for this?

Private Sub Command27_Click()
 'Update tbl_SR1 with Blood Data
     Dim db As DAO.Database
     Dim rs As DAO.Recordset
     
     Set db = CurrentDb
     Set rs = db.OpenRecordset("tbl_SR1", dbOpenDynaset)
     
     rs.AddNew
     rs.Fields("ProviderID") = Me.Text16
     rs.Fields("XM") = Me.txtXM
     rs.Fields("TX") = Me.txtTX
     
     rs.Fields("RptDate") = Me.Text20
     rs.Fields("XMPERC") = Format(Me.txtXM / Me.txtTX, "000.00")
     
     rs.Update
     
     rs.Close
     
     Set rs = Nothing
     
     'Clear All Selections and Return to Physician Evaluation Menu
     
     DoCmd.Close acForm, "frm_SR1"
     
 End Sub

thanks

Glen
0
Comment
Question by:GPSPOW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 2000 total points
ID: 39715673
Take a look at the tables design, and ensure that the XMPERC field has it's Length property set to Double (this property is found in the box under the list of fields, and defaults to Integer)

Then, write your equation like this:

rs.Fields("XMPERC") =  Me.txtXM / Me.txtTX

And handle the formatting through the field properties and/or through the textboxes used to display it.

If txtTX can ever be null or zero, you would need special handling to avoid errors:

If NZ(me.txtTX, 0) = 0 then
    ' do something to handle nulls and zeros to avoid division errors
Else
    if isnumeric( Me.txtXM ) = true then
         rs.Fields("XMPERC") =  Me.txtXM / Me.txtTX
    else
        ' Handle null or non-numeric txtXM)
    end if 
End if

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 39715679
<< Second I need to close the open form frmSR1 and reopen frmEvalMenu. >>

You've got the first part figured out (closing frmSR1).  This will open frmEvalMenu:

Docmd.OpenForm "EvalMenu"

But I recommend doing it in the reverse order.  Open the menu first, then close the frmSR1.  That way, you won't be left looking at a blank screen if frmEvalMenu takes a while to load:

  Docmd.OpenForm "EvalMenu"
  DoCmd.Close acForm, "frm_SR1"

Open in new window

0
 

Author Closing Comment

by:GPSPOW
ID: 39715682
Both solutions worked perfectly

Thanks

glen
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39715690
Glad to help :)
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question