form does not work after If statement

A

ANStech

I have code that opens a form from a cmdbutton.
Here it is:

Private Sub cmdOpenCalenderPopUp_Click()
Dim strWhereCond
strWhereCond = "ID = Forms!frmBatteries!ID"
DoCmd.OpenForm "frmTestCalenders", wherecondition:=strWhereCond
End Sub

I have other code that calls this sub when a condition is met:

Private Sub opgLocation_Click()
If Me!opgLocation = 2 Then
Call cmdOpenCalenderPopUp_Click
End If
End Sub

When the cmdbutton is clicked, the form appears, and I can add and edit data.

When the opgLocation is clicked, and the condition is true, the form opens,
but I cannot add or edit data. The only thing that works is the close button.

If I then try to go back to the cmdbutton, It behaves as the opgLocation.

What am I doing wrong??
 
R

RobFMS

I'm curious to know this.

Take this code:
Dim strWhereCond
strWhereCond = "ID = Forms!frmBatteries!ID"
DoCmd.OpenForm "frmTestCalenders",
wherecondition:=strWhereCond

and put in the place where you make the call "Call
cmdOpenCalenderPopUp_Click".

Do you get the same results or does it work just fine?


--
Rob

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
A

ANStech

I get the same result. Actually, I fixed the problem (and moved the code as
you suggsted) by using Refresh. I did this by trial and error and now it
works, but I am curious as to why one set of code would need this Refresh
and the other would not. In other words, When do I need Refresh? Does
If--Then cause a loop that "hangs up" the data refresh? If you know, please
reply, Otherwise, THANKS FOR YOUR INPUT!!!!!!!!!!!!!!!
 
Top