Cancel Command

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

Guest

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If
 
I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:
 
The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.
 
Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub
 
I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





Dan @BCBS said:
Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


Klatuu said:
The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.
 
Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


Klatuu said:
I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





Dan @BCBS said:
Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


Klatuu said:
The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

Dan @BCBS said:
Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


Klatuu said:
I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





Dan @BCBS said:
Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
Spelling is correct, it is a number, looking at strLinkCriteria - makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I tried that
and it tells me that is undefined - so how do I define it (Type statement in
the Module)....????



Klatuu said:
puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

Dan @BCBS said:
Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


Klatuu said:
I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
Aha, if strLinkCriteria is a number, then it is a syntax problem. The single
quotes need to be removed so SQL knows it is a number. Also see below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


Dan @BCBS said:
Spelling is correct, it is a number, looking at strLinkCriteria - makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I tried that
and it tells me that is undefined - so how do I define it (Type statement in
the Module)....????



Klatuu said:
puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

Dan @BCBS said:
Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
You have been so helpful - thank you!!

But, I'm getting:
User-Defined Type Not Defined
= Dim dbcurrent As CurrentDb

The Help is telling me to use the TYPE Statement in the module - but I
cannot figure out how to add a type and make this defined????

Thanks


Klatuu said:
Aha, if strLinkCriteria is a number, then it is a syntax problem. The single
quotes need to be removed so SQL knows it is a number. Also see below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


Dan @BCBS said:
Spelling is correct, it is a number, looking at strLinkCriteria - makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I tried that
and it tells me that is undefined - so how do I define it (Type statement in
the Module)....????



Klatuu said:
puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

:

Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
Sounds as though you're missing the reference to DAO.

While in the VB Editor, select Tools | References from the menu.

Scroll through the list of available references until you find the one for
"Microsoft DAO 3.6 Object Library" (assuming you're using Access 2000 or
newer: it'll be "Microsoft DAO 3.5 Object Library" or "Microsoft DAO 3.51
Object Library" for Access 97).

Select that reference by checking it, then get out of the dialog.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
You have been so helpful - thank you!!

But, I'm getting:
User-Defined Type Not Defined
= Dim dbcurrent As CurrentDb

The Help is telling me to use the TYPE Statement in the module - but I
cannot figure out how to add a type and make this defined????

Thanks


Klatuu said:
Aha, if strLinkCriteria is a number, then it is a syntax problem. The single
quotes need to be removed so SQL knows it is a number. Also see below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


Dan @BCBS said:
Spelling is correct, it is a number, looking at strLinkCriteria - makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I tried that
and it tells me that is undefined - so how do I define it (Type statement in
the Module)....????



:

puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

:

Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
I think you entered in incorrectly, what I posted was:
Dim dbcurrent as Database

Dan @BCBS said:
You have been so helpful - thank you!!

But, I'm getting:
User-Defined Type Not Defined
= Dim dbcurrent As CurrentDb

The Help is telling me to use the TYPE Statement in the module - but I
cannot figure out how to add a type and make this defined????

Thanks


Klatuu said:
Aha, if strLinkCriteria is a number, then it is a syntax problem. The single
quotes need to be removed so SQL knows it is a number. Also see below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


Dan @BCBS said:
Spelling is correct, it is a number, looking at strLinkCriteria - makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I tried that
and it tells me that is undefined - so how do I define it (Type statement in
the Module)....????



:

puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

:

Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
I will never rest until I get this!!
Syntax Error (missing operator) in query expression:

I have tried to fix this expression in a million ways and nothing is
working, do you see anything wrong with it??.


Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")


All the Code:

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent As Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = " & "" & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If








Klatuu said:
I think you entered in incorrectly, what I posted was:
Dim dbcurrent as Database

Dan @BCBS said:
You have been so helpful - thank you!!

But, I'm getting:
User-Defined Type Not Defined
= Dim dbcurrent As CurrentDb

The Help is telling me to use the TYPE Statement in the module - but I
cannot figure out how to add a type and make this defined????

Thanks


Klatuu said:
Aha, if strLinkCriteria is a number, then it is a syntax problem. The single
quotes need to be removed so SQL knows it is a number. Also see below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


:

Spelling is correct, it is a number, looking at strLinkCriteria - makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I tried that
and it tells me that is undefined - so how do I define it (Type statement in
the Module)....????



:

puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

:

Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
You now have a comma (",") on the end of the SQL statement where you should
have a semi-colon (";").

--
Brendan Reynolds
Access MVP

Dan @BCBS said:
I will never rest until I get this!!
Syntax Error (missing operator) in query expression:

I have tried to fix this expression in a million ways and nothing is
working, do you see anything wrong with it??.


Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")


All the Code:

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent As Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = " & "" & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If








Klatuu said:
I think you entered in incorrectly, what I posted was:
Dim dbcurrent as Database

Dan @BCBS said:
You have been so helpful - thank you!!

But, I'm getting:
User-Defined Type Not Defined
= Dim dbcurrent As CurrentDb

The Help is telling me to use the TYPE Statement in the module - but I
cannot figure out how to add a type and make this defined????

Thanks


:

Aha, if strLinkCriteria is a number, then it is a syntax problem.
The single
quotes need to be removed so SQL knows it is a number. Also see
below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry
where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


:

Spelling is correct, it is a number, looking at strLinkCriteria -
makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I
tried that
and it tells me that is undefined - so how do I define it (Type
statement in
the Module)....????



:

puzzlement. Is icnno spelled correctly? Is it text? step
through in debug
to see what strLinkCriteria is before you do the openrecordset.
Also I did a
typo, but it will not affect anything. I notice you created an
object
dbcurrent, and I, in haste, type it as currentdb. You might want
to change
it.

Let me know what happens

:

Some clean up??? If I could rewrite code that quick I'd be the
VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set
rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry
where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad,
but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether
a user clicked
cancel or just closed the input box with no entery. Instead
of a cancel
event, we can use that value to determine whether to
continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria &
"'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from
t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a
MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please
Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from
t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know
you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access
write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code
you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan
code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned
developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put
it in the click event
of the button. Then you can add this code to open
your form. Where you
will put it depends on what else is happening in the
code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for
information via a macro.
My question is, if Cancel is pressed I need it to
open a form... I have ON
EXIT set to a macro to open a form (but form don't
open).. I have Default and
Cancel both set to YES.... I wish there was a ON
CANCEL command!!!!

Can you please help me open a from when Cancel is
clicked?

Thanks
 
'It is this way if icnno is a string field:
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
'It is this way if icno is a number field:
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = dbcurrent.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")


Dan @BCBS said:
I will never rest until I get this!!
Syntax Error (missing operator) in query expression:

I have tried to fix this expression in a million ways and nothing is
working, do you see anything wrong with it??.


Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")


All the Code:

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent As Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = " & "" & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If








Klatuu said:
I think you entered in incorrectly, what I posted was:
Dim dbcurrent as Database

Dan @BCBS said:
You have been so helpful - thank you!!

But, I'm getting:
User-Defined Type Not Defined
= Dim dbcurrent As CurrentDb

The Help is telling me to use the TYPE Statement in the module - but I
cannot figure out how to add a type and make this defined????

Thanks


:

Aha, if strLinkCriteria is a number, then it is a syntax problem. The single
quotes need to be removed so SQL knows it is a number. Also see below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


:

Spelling is correct, it is a number, looking at strLinkCriteria - makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I tried that
and it tells me that is undefined - so how do I define it (Type statement in
the Module)....????



:

puzzlement. Is icnno spelled correctly? Is it text? step through in debug
to see what strLinkCriteria is before you do the openrecordset. Also I did a
typo, but it will not affect anything. I notice you created an object
dbcurrent, and I, in haste, type it as currentdb. You might want to change
it.

Let me know what happens

:

Some clean up??? If I could rewrite code that quick I'd be the VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad, but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether a user clicked
cancel or just closed the input box with no entery. Instead of a cancel
event, we can use that value to determine whether to continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put it in the click event
of the button. Then you can add this code to open your form. Where you
will put it depends on what else is happening in the code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for information via a macro.
My question is, if Cancel is pressed I need it to open a form... I have ON
EXIT set to a macro to open a form (but form don't open).. I have Default and
Cancel both set to YES.... I wish there was a ON CANCEL command!!!!

Can you please help me open a from when Cancel is clicked?

Thanks
 
If the ICN number is text, you need

strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"

Exagerated for clarity, that's

strLinkCriteria = "[icnno] = ' " & strLinkCriteria & " ' "

If it a number, you want:

strLinkCriteria = "[icnno] = " & strLinkCriteria

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dan @BCBS said:
I will never rest until I get this!!
Syntax Error (missing operator) in query expression:

I have tried to fix this expression in a million ways and nothing is
working, do you see anything wrong with it??.


Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")


All the Code:

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent As Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = " & "" & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry where " _
& stLinkCriteria & ",")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If








Klatuu said:
I think you entered in incorrectly, what I posted was:
Dim dbcurrent as Database

Dan @BCBS said:
You have been so helpful - thank you!!

But, I'm getting:
User-Defined Type Not Defined
= Dim dbcurrent As CurrentDb

The Help is telling me to use the TYPE Statement in the module - but I
cannot figure out how to add a type and make this defined????

Thanks


:

Aha, if strLinkCriteria is a number, then it is a syntax problem.
The single
quotes need to be removed so SQL knows it is a number. Also see
below for
correct Dim statement:

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
Dim dbcurrent as Database

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = " & strLinkCriteria
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry
where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If


:

Spelling is correct, it is a number, looking at strLinkCriteria -
makes me
think Am I missing a DIM example DIM dbcurrent As Database. So I
tried that
and it tells me that is undefined - so how do I define it (Type
statement in
the Module)....????



:

puzzlement. Is icnno spelled correctly? Is it text? step
through in debug
to see what strLinkCriteria is before you do the openrecordset.
Also I did a
typo, but it will not affect anything. I notice you created an
object
dbcurrent, and I, in haste, type it as currentdb. You might want
to change
it.

Let me know what happens

:

Some clean up??? If I could rewrite code that quick I'd be the
VP of IT !!!

The Compiler is saying Sytax error in where clause: "Set
rstemp...where"
Suggestions???

Private Sub Command0_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OPENFORM "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from t_Entry
where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If
End Sub


:

I made a few changes here (once i got over the giggles :)
(not really, I never laugh at anyone, your code is not bad,
but needs some
clean up)

As there is not Cancel in a Click event, we can tell whether
a user clicked
cancel or just closed the input box with no entery. Instead
of a cancel
event, we can use that value to determine whether to
continue.

Private Sub Command1_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset

strLinkCriteria = InputBox("Please Enter the ICN Number")

If Len(Trim(strLinkCriteria)) = 0 Then
DoCmd.OpenForm "f_Menu"
Else
strLinkCriteria = "[icnno] = '" & strLinkCriteria &
"'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from
t_Entry where " _
& stLinkCriteria & ";")
If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
rstemp.Close
Set rstemp = Nothing
Set dbcurrent = Nothing
Exit Sub
End If
End If





:

Don't laugh, this SQL has taken me a long time..
I'm trying to:
A. Pop Up with "Please Enter the ICN Number"
click ok and it takes you to that record..

B. If CANCEL is clicked it takes you to a form.

C. If no number is entered, or number does not exist a
MsgBox "There is no
record for this ICN Number." appears.

If you run it - I think you will see what I'm trying to do:


Private Sub Command1_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim rstemp As Recordset
stLinkCriteria = "[icnno]=" & "'" & InputBox("Please
Enter the ICN
Number") & "'"
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from
t_Entry where " &
stLinkCriteria & ";")

If Cancel = True Then
DoCmd.OpenForm "f_Menu"
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number."
Exit Sub
End If


End Sub


:

The click event has no cancel argument. How do you know
you want to cancel?
Convert the macro code to VBA and post that.

:

I agree, it's just sometimes quicker to let Access
write the VBA, then work
with it.
Obviously not in this case... The "If Cancel..." code
you suggested doe not
work within the VBA (Before or after the String).

If you could help me convert this Macro-VBA to plan
code not using a Macro,
I can start doing it that way all the time...

Thanks



Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
stDocName = "m_EditAppeal"
DoCmd.RunMacro stDocName

If Cancel = True Then
DoCmd.OpenForm "f_Main"
End If

Exit_Command4_Click:



:

This is another example of why most seasoned
developers don't use macros.
They are very limited.

I would suggest you convert your macro to VBA and put
it in the click event
of the button. Then you can add this code to open
your form. Where you
will put it depends on what else is happening in the
code.

If Cancel = True Then
DoCmd.OpenForm "MyFormName"
End If


:

On my form I have a command button, it asks for
information via a macro.
My question is, if Cancel is pressed I need it to
open a form... I have ON
EXIT set to a macro to open a form (but form don't
open).. I have Default and
Cancel both set to YES.... I wish there was a ON
CANCEL command!!!!

Can you please help me open a from when Cancel is
clicked?

Thanks
 
Back
Top