![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I created a query in Access 2000 that runs perfectly. I then copied the "sql" version of the same query and set it equal the variable "sql" in the code below. When I run the code below I get an "Type Mismatch" error. Can someone explain how to fix this? Thanks, TD Private Sub cmdSave_Click() On Error GoTo Err_cmdSave_Click Dim db As Database Dim rst As Recordset Dim sql As String [Forms]![frmVendorSetup]![Name].SetFocus sql = "SELECT tblVendors.Name FROM tblVendors WHERE (((tblVendors.Name) Like [Forms]![frmVendorSetup]![Name].[Text] & " * "));" Set db = OpenDatabase("adsi.mdb") Set rst = db.OpenRecordset(sql, dbOpenSnapshot) If rst.RecordCount > 0 Then MsgBox "This vendor may already exist, check again!", vbOKOnly, WAIT!: GoTo Exit_cmdSave_Click: GoTo Exit_cmdSave_Click: ElseIf rst.RecordCount = 0 Then DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 cboName.Requery GoTo Exit_cmdSave_Click: End If Exit_cmdSave_Click: Exit Sub Err_cmdSave_Click: MsgBox Err.Description Resume Exit_cmdSave_Click End Sub |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
You'll need to resolve the reference to the form's control by concatenating it outside the text string. sql = "SELECT tblVendors.Name FROM tblVendors WHERE (((tblVendors.Name) Like '" & [Forms]![frmVendorSetup]![Name].[Text] & "*'));" -- Ken Snell MS ACCESS MVP "TD" <tdlee (AT) mindspring (DOT) com> wrote Thanks Ken. I made the changes you suggested but now I get this error message "Too few parameters. Expect 1" Any suggestions? Thanks again TD |
#5
| |||
| |||
|
|
Thanks Ken. I made the changes you suggested but now I get this error message "Too few parameters. Expect 1" Any suggestions? Thanks again TD |
#6
| |||
| |||
|
|
Ken, I tried what you suggested but I get the "Type mismatch" error again. Here is the sql statement, all on one line of course: sql = "SELECT tblVendors.Name FROM tblVendors WHERE (((tblVendors.Name) Like '" & [Forms]![frmVendorSetup]![Name].[text] & "*'));" Thanks in advance for your help!!! "Ken Snell" <kthsneisllis9 (AT) ncoomcastt (DOT) renaetl> wrote in message news:r4CdnSkJDp3l3T7cRVn-qw (AT) comcast (DOT) com... You'll need to resolve the reference to the form's control by concatenating it outside the text string. sql = "SELECT tblVendors.Name FROM tblVendors WHERE (((tblVendors.Name) Like '" & [Forms]![frmVendorSetup]![Name].[Text] & "*'));" -- Ken Snell MS ACCESS MVP "TD" <tdlee (AT) mindspring (DOT) com> wrote in message news:5eAod.1$if4.0 (AT) fe12 (DOT) lga... Thanks Ken. I made the changes you suggested but now I get this error message "Too few parameters. Expect 1" Any suggestions? Thanks again TD |
![]() |
| Thread Tools | |
| Display Modes | |
| |