By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

Parameter type append query dialog box - how to abort smoothly?

P: n/a
MLH
I have the following code in an Access 97 procedure:

MySQL = "INSERT INTO tblVehicleNames (VehicleMake) SELECT [Enter the
make] AS [NewMakenModel];"
DoCmd.SetWarnings False
DoCmd.RunSQL (MySQL)
DoCmd.SetWarnings True

When it runs, a dialog box instructing me to "Enter the make". It
is expecting me to type in something like "Chevy Caprice". The dialog
box has 2 buttons: OK and Cancel. If I enter nothing at all and click
"OK", nothing happens. No record is appended to tblVehicleNames and
no error occurs. However, if I click "Cancel", error #2766 occurs. Why
does "Cancel" result in an error when "OK" does not?
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Use an inputbox to ask them the make before you build your sql string.
Like this;

Dim strRetVal as String, mySQL as String

strRetVal = Inputbox("Enter the make")

If Len(strRetVal) > 0 Then 'only proceed if they enter something
mySQL = "INSERT INTO tblVehicleNames(VehicleMake) VALUES ('" &
strRetVal & "')"
DoCmd.Setwarnings False
DoCmd.RunSQL (MySQL)
DoCmd.SetWarnings True
Else ' If you want, you can tell them what they did wrong
msgbox "Must enter a vehicle make"
End If

This code is not pretty but it gives you the general idea.

Nov 13 '05 #2

P: n/a
MLH
Good suggestion, Wolf. Many thx!
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Use an inputbox to ask them the make before you build your sql string.
Like this;

Dim strRetVal as String, mySQL as String

strRetVal = Inputbox("Enter the make")

If Len(strRetVal) > 0 Then 'only proceed if they enter something
mySQL = "INSERT INTO tblVehicleNames(VehicleMake) VALUES ('" &
strRetVal & "')"
DoCmd.Setwarnings False
DoCmd.RunSQL (MySQL)
DoCmd.SetWarnings True
Else ' If you want, you can tell them what they did wrong
msgbox "Must enter a vehicle make"
End If

This code is not pretty but it gives you the general idea.


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.