Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 2196 That I Never Had Before

Status
Not open for further replies.

oxicottin

Programmer
Jun 20, 2008
353
US
Hello, I recently added a select case to a form and now I am getting this error BUT I don't get the error all the time only sometimes. Here is what I found, if I open the form and click the OK button (cmdLogin)it gives me the:

Run-time error ‘2196’:
Microsoft Office Database cant retrieve the value of this property.

and debug takes me to:

Code:
If Me.txtPassword.Text <> "soggycashew" Then

Now if I open the form and first click into the password box then click the OK button then it works like its supposed to it gives the correct message. I think for some reason the text box (txtPassword)doesn't have focus when the OK button is pressed but the first thing in the VBA for the button is to SetFocus. The next bit of code is from the form (frmSwitchboard)that has the option group and I set it to visible = false. Any thoughts?

Code:
Private Sub cmdOption5_Click()

If IsNull(Me.fmAdminGroup) Then
     MsgBox "Please select a Option!", vbCritical, "Selection Error"
       Me.fmAdminGroup.SetFocus
    Exit Sub
Else
    DoCmd.OpenForm "frmPasswordRequired", acNormal
    Forms!frmSwitchboard.Visible = False 'Hides the switchboard
End If


End Sub

Thanks,
Chad


Thanks,
SoggyCashew.....
 
it is likely a timing issue, with some competing events. Try the following

doevents
me.txtPassword.setfocus
If Me.txtPassword.Text <> "soggycashew" Then

if that does not work change to

me.dirty = false
If me.txtPassword.value <> "soggycashew" Then
 
Majp, Im not sure if i understand what you want me to try in your first sugestion, after reading your post it seems you want me to add "doevents" to the line above the setfocus. If so I have done that and still get the same error. I had also tried your second sugestion of adding (me.dirty = false) and I removed the setfocus and when I click the OK button it does nothing and if I clik in the txtpassword box and select OK it does nothing. If I use the dirty and setfocus then the error comes back. Any thoughts?



Thanks,
SoggyCashew.....
 
1) To retreive a controls text property the control has to have focus. Therefore hardly ever use it when the value property is available, beacuase you can always reference the value property. However, on a bound form there is a point of time when the text has been entered into a control, but the controls value has not yet been updated. The form is "dirty". If you set the form's dirty property to false it saves all control values, and whatever you see in the text property is equivalent to the value property

So
me.dirty = false
'guarantees whatever is in the text is the same as the controls value
'now should simply be able to reference the value
If Me.txtPassword <> "soggycashew" then

2) When you move around a form multiple events happen, not just one. Example you enter the control, it gets focus, and the form's on current event may all happen at the same time. These events cache up and then compete with your code.
doevents
give control back to the processor so that all events first finish

In you case you set focus on the control, but some event is not finish and it takes focus away momentarally. That is why sometimes the code works and sometimes is does not. By calling doevents it lets all the events finish first, then you set focus.

To debug this do the following

me.dirty = false
msgbox Me.txtPassword & " Is not equal SC: " & Me.txtPassword <> "soggycashew"
If Me.txtPassword <> "soggycashew" then ...
 
Majp, I tried the snipit you posted and when form is opened it wont let me use the me.dirty, it gives me an error 2455 invalid reference to the property dirty(most likely im doing something wrong). So i removed the dirty and it gives me a msg box that says true then the origional 2196 error comes up. here is what i used:

Code:
'Ensure focus on the TextBox
 Me.txtPassword.SetFocus
 
 'Me.Dirty = False
 MsgBox Me.txtPassword & " Is not equal SC: " & Me.txtPassword <> "soggycashew"


 'Read the text within the TextBox and see if it contains
 'our desired Password...If it does not then...
 If Me.txtPassword.Text <> "soggycashew" Then
 
    'No it doesn't so...
    'Increment out Password entry counter
    Cnt = Cnt + 1
    'If the Counter (Cnt) = 3 then the Password was
    'unsuccessfuly entered three times...
    If Cnt = 3 Then.....



Thanks,
SoggyCashew.....
 
I am assuming your form is then unbound. An unbound form does not have a dirty property because there is no underlying field to commit the text to.

So you should not have to worry about me.dirty and the text should be the same as the value. It appears you proved that since you got true saying that the password <> "soggycashew"

So I was suggesting then just to use the value property

'Me.Dirty = False
MsgBox Me.txtPassword & " Is not equal SC: " & Me.txtPassword <> "soggycashew"


'Read the text within the TextBox and see if it contains
'our desired Password...If it does not then...

'so use the value property instead of the text here
'value is the default so you do not have to write it
'me.txtpassword.value is the same as me.txtpassword
If Me.txtPassword <> "soggycashew" Then
 
Majp, yes the form is unbound and I have tried just using line below and what it does is just skip having to put a password in the textbox and goes straight to opening the form that I selected from my option group.

If Me.txtPassword <> "soggycashew" Then

If I use the code below, here is what it does.
1) msgbox opens up and says true so I click "OK"
2) Then it goes straight to opening the form that I selected from my option group.

Code:
Private Sub cmdLogin_Click()
 Static Cnt As Integer
 
 'Trap Errors
 On Error GoTo Error_cmdLogin
 
 'Ensure focus on the TextBox
 Me.txtPassword.SetFocus
 
 'Me.Dirty = False
 MsgBox Me.txtPassword & " Is not equal SC: " & Me.txtPassword <> "soggycashew"

 If Me.txtPassword <> "soggycashew" Then
 
    'No it doesn't so...
    'Increment out Password entry counter
    Cnt = Cnt + 1
    'If the Counter (Cnt) = 3 then the Password was
    'unsuccessfuly entered three times...
    If Cnt = 3 Then.....

Thanks,
SoggyCashew.....
 
It sounds like your code is working, just the logic is not correct.

if the user enters something besides "soggycashew" then
it enters the if check. That seems correct.

but here is your problem
DoCmd.OpenForm "frmPasswordRequired", acNormal
Forms!frmSwitchboard.Visible = False 'Hides the switchboard

When you open a form the only way to stop the code is to open the form in dialog. "acDialog". I think it is like the 4th or 5th parameter of the open form method. Since you did not open it dialog the code just keeps going to the next line and hides you switchboard and runs any code after that.

What is the rest of the code in your cmdlogin also.
 
I think were mixed up on what code is where. the code:

but here is your problem
DoCmd.OpenForm "frmPasswordRequired", acNormal
Forms!frmSwitchboard.Visible = False 'Hides the switchboard

is on my switchboard that opens the frmPasswordRequired which is the example I put on mediaFire.

Im at the point where I just want something that I can use the case select and have a password...

Thanks,
SoggyCashew.....
 
Majp, Im going to upload the switchboard and password forms to MediaFire when I get outa work tonight.... I cant do it at work because the site is blocked. This way you can see exactly what im doing wrong..... Thanks!

Thanks,
SoggyCashew.....
 
As far as I can tell, from what you are saying, your code is executing as designed, but sounds as if your logic is incorrect. Please post the remainder of you login code.
 
Majp, I found out why it wasnt working and I really dont know why it was causing the error but its working like its suposed to now.

I had the txtPassword's Input Mask set to Password and when I removed it and tried it everything worked.... WHY?

Thanks,
SoggyCashew.....
 
MajP, is there an explamation on why this solved my problem?

Thanks,
Chad

Thanks,
SoggyCashew.....
 
I have not looked at your db, if I get time I will check it out. There is not enough code posted for me to see how the code flows, so I cannot see where the problem was or what the problem was.

Although this has nothing to do with your current issue, something to keep in mind with input masks. There are three parameters on the mask
the first is the format
the second is do you store the literal characters
the third is the default character

if you choose to store the literal then
a format of this (999) 999-9999 would store the number as
(312) 123-4321
if not you would see it in the above format but the number is stored as
3121234321
something to keep in mind when you compare or query the value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top