Solved

Option button keeps value across records

Posted on 2011-09-26
9
231 Views
Last Modified: 2012-05-12
I created the code to click a option button on record, which turns a label visible, enables a cmd button and disables a text box. All of that works, but when I navigate to the next record the option button value keeps its value across the next record, and I don't want that, what I am missing??
Option Compare Database
Option Explicit



Private Sub Form_Current()
If Me.optAsset.Value = -1 Then
Me!lblAsset.Visible = True
Me!cmdUpdateID.Enabled = True
Me!AssetNo.Enabled = False
Else: Me!AssetNo.Enabled = True
Me!lblAsset.Visible = False
Me!cmdUpdateID.Enabled = False
End If
End Sub


Private Sub optAsset_Click()
If optAsset.Value = -1 Then
Me.lblAsset.Visible = True
Me.cmdUpdateID.Enabled = True
Me.AssetNo.Enabled = False
Me.Comment = (Date & " -- No ID was found on Equipment, please notify Department of use to fix this issue.")
Else
Me.lblAsset.Visible = False
Me.cmdUpdateID.Enabled = False
Me.AssetNo.Enabled = True
End If
End Sub

Private Sub cmdUpdateID_Click()
Dim i As String
i = InputBox("Enter Asset ID Number", "Asset ID")
Me.AssetNo.Enabled = True
Me.AssetNo = i
Me.optAsset.Value = 0
Me.lblAsset.Visible = False
Me.Comment = (Date & "  --  ID found and affixed to equipment")

End Sub

Open in new window

0
Comment
Question by:Engtech05
  • 3
  • 3
  • 3
9 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
is the option "optAsset" bound to a field in the table?
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility

 You need to bind the control to a field in the record by setting it's controlsource or you need to assign the default value you want in the forms OnCurrent event, which fires when a record receives the focus.

Jim.
0
 

Author Comment

by:Engtech05
Comment Utility
Ok the option button is not bound to anything, and I really dont need it to be. How do I get it to quit bringing everything over, the label the cmd button, I think I have got the option button, just not sure about the others.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
<Ok the option button is not bound to anything, and I really dont need it to be>

then, you can not achieved what you are trying to do , using the form current event.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Engtech05
Comment Utility
Good to know in the future, so what do I need to do to fix this then. Can I bind it to the AssetNo field with it showing text "Unknown ID", if so how. I know how to bind it just no the text portion.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
try adding a YESNo field to your table and bind the optAsset to that field.
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
Comment Utility
OnCurrent event:

If NZ(Me.AssetNo,"") = "" then
  ' No Asset ID
  Me.lblAsset.Visible = True
  Me.cmdUpdateID.Enabled = True
  Me.AssetNo.Enabled = False
  Me.Comment = (Date & " -- No ID was found on Equipment, please notify Department of use to fix this issue.")
  Me.optAsset.Value = -1
Else
 ' Asset ID
  Me.lblAsset.Visible = False
  Me.cmdUpdateID.Enabled = False
  Me.AssetNo.Enabled = True
  Me.Comment = (Date & "  --  ID found and affixed to equipment")
  Me.optAsset.Value = 0
End If

Jim.
0
 

Author Closing Comment

by:Engtech05
Comment Utility
Thanks Jim, really helpful. I appreciate the assistance.
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
Not a problem.

As an add-on, anytime your working with unbound controls on a form, I like to put all the logic for setting the "state" of things in a sub procedure in the form iteself.  ie.:

Procedure Sub SetFormControls()

If NZ(Me.AssetNo,"") = "" then
  ' No Asset ID
  Me.lblAsset.Visible = True
  Me.cmdUpdateID.Enabled = True
  Me.AssetNo.Enabled = False
  Me.Comment = (Date & " -- No ID was found on Equipment, please notify Department of use to fix this issue.")
  Me.optAsset.Value = -1
Else
 ' Asset ID
  Me.lblAsset.Visible = False
  Me.cmdUpdateID.Enabled = False
  Me.AssetNo.Enabled = True
  Me.Comment = (Date & "  --  ID found and affixed to equipment")
  Me.optAsset.Value = 0
End If

End Sub

  Then from the OnCurrent, you would do:

  Call SetFormControls()

 and the same from the AfterUpdate event of the control itself or any place else that you might be changing the state of the control or what it's tied to.

  This allows you to keep one copy of the code rather then having it in multiple places.

  That may not work in this case because on one hand your checking the field and setting the state of the controls, but in the update your checking the state of the control and setting the reset of the controls and the field.

Jim.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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 …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now