DoCmd.OpenForm problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Please excuse the double post but I need resolution to this annoying problem.

To help a user make corrections to previously entered data, I’ve given them
a form to enter a transaction key and click an OK button. This then takes
the user to yet another form, which displays the data they wish to correct.

The problem is that the user has to click the OK button twice to get the
data to display. The first time they click OK, the second form opens up and
the second time they click OK, the data appears. I used the button wizard to
build the code that opens the form. The code is as follows:

Private Sub butOpenfrmLeaveCorrection_Click()
On Error GoTo Err_butOpenfrmLeaveCorrection_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmEmpLeaveCorrection"

stLinkCriteria = "[LeaveID]=" & Me![boxLID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_butOpenfrmLeaveCorrection_Click:
Exit Sub

Err_butOpenfrmLeaveCorrection_Click:
MsgBox Err.Description
Resume Exit_butOpenfrmLeaveCorrection_Click

End Sub

Why doesn't the second form open up with data the first time? What is the
way to get the second form’s data to display the first time the user clicks
the OK button.

tia,
 
JMorrell said:
Please excuse the double post but I need resolution to this annoying problem.

To help a user make corrections to previously entered data, I've given them
a form to enter a transaction key and click an OK button. This then takes
the user to yet another form, which displays the data they wish to correct.

The problem is that the user has to click the OK button twice to get the
data to display. The first time they click OK, the second form opens up and
the second time they click OK, the data appears. I used the button wizard to
build the code that opens the form. The code is as follows:

Private Sub butOpenfrmLeaveCorrection_Click()
On Error GoTo Err_butOpenfrmLeaveCorrection_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmEmpLeaveCorrection"

stLinkCriteria = "[LeaveID]=" & Me![boxLID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_butOpenfrmLeaveCorrection_Click:
Exit Sub

Err_butOpenfrmLeaveCorrection_Click:
MsgBox Err.Description
Resume Exit_butOpenfrmLeaveCorrection_Click

End Sub

Why doesn't the second form open up with data the first time? What is the
way to get the second form's data to display the first time the user clicks
the OK button.

Is the data on the first form perhaps not saved yet? If you think that might be
it add the line...

Me.Dirty = False

to your code (before the OpenForm line)
 
Thanks for the quick reply!

Actually, the data on the first form doesn't need to be saved. The form/data
is just a means to open the correction form to the correct record.

I tried the Me.Dirty = False and got the following error: "You entered an
expression that has an invalid reference to the property Dirty." ??

JMorrell



Rick Brandt said:
JMorrell said:
Please excuse the double post but I need resolution to this annoying problem.

To help a user make corrections to previously entered data, I've given them
a form to enter a transaction key and click an OK button. This then takes
the user to yet another form, which displays the data they wish to correct.

The problem is that the user has to click the OK button twice to get the
data to display. The first time they click OK, the second form opens up and
the second time they click OK, the data appears. I used the button wizard to
build the code that opens the form. The code is as follows:

Private Sub butOpenfrmLeaveCorrection_Click()
On Error GoTo Err_butOpenfrmLeaveCorrection_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmEmpLeaveCorrection"

stLinkCriteria = "[LeaveID]=" & Me![boxLID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_butOpenfrmLeaveCorrection_Click:
Exit Sub

Err_butOpenfrmLeaveCorrection_Click:
MsgBox Err.Description
Resume Exit_butOpenfrmLeaveCorrection_Click

End Sub

Why doesn't the second form open up with data the first time? What is the
way to get the second form's data to display the first time the user clicks
the OK button.

Is the data on the first form perhaps not saved yet? If you think that might be
it add the line...

Me.Dirty = False

to your code (before the OpenForm line)
 
JMorrell said:
Thanks for the quick reply!

Actually, the data on the first form doesn't need to be saved. The form/data
is just a means to open the correction form to the correct record.

I tried the Me.Dirty = False and got the following error: "You entered an
expression that has an invalid reference to the property Dirty." ??

JMorrell

To reduce the problem to its basics...

When you open a form with DoCmd.OpenForm and supply a WHERE argument and the
resulting form opens up blank, then that means there are zero records satisfying
the WHERE argument. So step one should be to isolate that and determine if it
is correct.

Put a break-point on the DoCmd.OpenForm line and when the code pauses there
enter the following into the immediate pane of the debug window.

?stLinkCriteria <Enter>

....and see what the result is.
 
Thanks for working with me on this.

I know for a fact that there is indeed a record that matches what is entered
on the first form. I don't think that theory works because if the user hits
the OK button again (on the first form), the second form then displays the
correct data. If the user keeps the second form open and enters another
transaction key number and clicks OK, the second form goes directly to that
record. It's only when the second form pops up for the first time that the
user has to click the OK button twice.

I put a debug.print stLinkCriteria and saw "[LeaveID]=4860" (without
quotes). This is indeed a valid LeaveID number.

I know it's something easy that I'm just not seeing. That's the frustrating
thing about this annoyance.

JMorrell
 
I found it.

The correct statement should be:
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, acFormEdit

Trial/error works wonders!

thanks again for your help!

JMorrell
 
JMorrell said:
I found it.

The correct statement should be:
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, acFormEdit

Trial/error works wonders!

thanks again for your help!

Just to point out though that this is only the case if the default behavior of
the form is to open in DataEntry mode in which case no existing records are
displayed. If the default were to open at "record 1 of n" then you wouldn't
need the acFormEdit argument on the statement.
 
Back
Top