Solved

Option button keeps value across records

Posted on 2011-09-26
9
234 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36599546
is the option "optAsset" bound to a field in the table?
0
 
LVL 57
ID: 36599557

 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
ID: 36599679
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36599716
<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
 

Author Comment

by:Engtech05
ID: 36599735
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36599760
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
ID: 36599779
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
ID: 36599819
Thanks Jim, really helpful. I appreciate the assistance.
0
 
LVL 57
ID: 36599913
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

803 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