G
gsnidow via AccessMonster.com
Greetings folks. This might be easy for some of you, but it is stumping me.
I have a datasheet form with a field, 'BATCH', whose double click event
opens a popup with info pertinent to the current record. The record source
of the popup is a stored procedure. Sometimes, when I double click I get the
following error:
'Microsoft Office Access can't find the form 'frmCable_Reel_Notes' referred
to in a macro expression or Visual Basic code'
Then if I hit ok and double click again the form opens up no problem. It
happens about one out of every four times I try it. Below is the code behind
the double click event of the datasheet BATCH field. Thanks for your time.
********************************************************************************************
Private Sub BATCH_DblClick(Cancel As Integer)
On Error GoTo err_BATCH_DblClick
Dim cn As ADODB.Connection
Dim rstblreel_notes As ADODB.Recordset
Dim strSQL As String
Dim strSQLI As String
Dim boolDupId As Boolean
'Checks to see if a record already exists for current batch and reel
strSQL = "SELECT batch, reel_num FROM tblreel_notes " & _
"WHERE batch = '" & Me.BATCH.Value & "' " & _
"AND reel_num = '" & Me.REEL.Value & "'"
'Inserts record into tblreel_notes if no record currently exists
strSQLI = "INSERT INTO tblreel_notes (reel_num,batch,reel_id) " & _
"VALUES ('" & Me.REEL.Value & "','" & Me.BATCH.Value & "','"
& Me.id.Value & "') "
boolDupId = False
Set rstblreel_notes = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rstblreel_notes.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
'Make sure batch is in proper format --Thanks OldPro
If Len("" & Me.BATCH) = 10 And IsNumeric(Me.BATCH) And Val(Mid(Me.BATCH, 1,
2)) < 13 Then
If rstblreel_notes.EOF Then
boolDupId = False
DoCmd.RunSQL strSQLI
Else
'I think this is where the problem is, since this is the only
'place where the form is opened. If the form is already
opened
'the requery works fine.
If Not CurrentProject.AllForms("frmCable_Reel_Notes").
IsLoaded Then
stDocName = "frmCable_Reel_Notes"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
Forms!frmCable_Reel_Notes.Requery
If CurrentProject.AllForms("frmCable_Reel_History").IsLoaded Then
Forms!frmCable_Reel_History.Requery
End If
Else
MsgBox "Enter a valid batch#", vbOKCancel
End If
rstblreel_notes.Close
Cancel = boolDupId
exit_BATCH_DblClick:
Exit Sub
err_BATCH_DblClick:
MsgBox Err.Description
Resume exit_BATCH_DblClick
End Sub
*******************************************************************************************
I have a datasheet form with a field, 'BATCH', whose double click event
opens a popup with info pertinent to the current record. The record source
of the popup is a stored procedure. Sometimes, when I double click I get the
following error:
'Microsoft Office Access can't find the form 'frmCable_Reel_Notes' referred
to in a macro expression or Visual Basic code'
Then if I hit ok and double click again the form opens up no problem. It
happens about one out of every four times I try it. Below is the code behind
the double click event of the datasheet BATCH field. Thanks for your time.
********************************************************************************************
Private Sub BATCH_DblClick(Cancel As Integer)
On Error GoTo err_BATCH_DblClick
Dim cn As ADODB.Connection
Dim rstblreel_notes As ADODB.Recordset
Dim strSQL As String
Dim strSQLI As String
Dim boolDupId As Boolean
'Checks to see if a record already exists for current batch and reel
strSQL = "SELECT batch, reel_num FROM tblreel_notes " & _
"WHERE batch = '" & Me.BATCH.Value & "' " & _
"AND reel_num = '" & Me.REEL.Value & "'"
'Inserts record into tblreel_notes if no record currently exists
strSQLI = "INSERT INTO tblreel_notes (reel_num,batch,reel_id) " & _
"VALUES ('" & Me.REEL.Value & "','" & Me.BATCH.Value & "','"
& Me.id.Value & "') "
boolDupId = False
Set rstblreel_notes = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rstblreel_notes.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
'Make sure batch is in proper format --Thanks OldPro
If Len("" & Me.BATCH) = 10 And IsNumeric(Me.BATCH) And Val(Mid(Me.BATCH, 1,
2)) < 13 Then
If rstblreel_notes.EOF Then
boolDupId = False
DoCmd.RunSQL strSQLI
Else
'I think this is where the problem is, since this is the only
'place where the form is opened. If the form is already
opened
'the requery works fine.
If Not CurrentProject.AllForms("frmCable_Reel_Notes").
IsLoaded Then
stDocName = "frmCable_Reel_Notes"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If
Forms!frmCable_Reel_Notes.Requery
If CurrentProject.AllForms("frmCable_Reel_History").IsLoaded Then
Forms!frmCable_Reel_History.Requery
End If
Else
MsgBox "Enter a valid batch#", vbOKCancel
End If
rstblreel_notes.Close
Cancel = boolDupId
exit_BATCH_DblClick:
Exit Sub
err_BATCH_DblClick:
MsgBox Err.Description
Resume exit_BATCH_DblClick
End Sub
*******************************************************************************************