Solved

Option button keeps value across records

Posted on 2011-09-26
9
236 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
[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
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

740 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