From: Micki on
I am trying for a simple way to have an unbound control auto-filled based on
another field on the form. I keep getting a syntax error no matter how I
have manipluated my OpenRecordSet statement. Currently, I have

Private Sub Form_Current()
Dim strClient As DAO.Recordset

Set strClient = CurrentDb.OpenRecordset ("SELECT Customer" & "FROM
tblCustomers" & "WHERE CustomerID=" & "Forms!frmJobs!Cust")
Me.ClientName = strClient

End Sub

Can some one please point out my error?
From: Stuart McCall on
"Micki" <Micki(a)discussions.microsoft.com> wrote in message
news:9D074C47-4438-42DD-9CC6-63CEE86816AD(a)microsoft.com...
>I am trying for a simple way to have an unbound control auto-filled based
>on
> another field on the form. I keep getting a syntax error no matter how I
> have manipluated my OpenRecordSet statement. Currently, I have
>
> Private Sub Form_Current()
> Dim strClient As DAO.Recordset
>
> Set strClient = CurrentDb.OpenRecordset ("SELECT Customer" & "FROM
> tblCustomers" & "WHERE CustomerID=" & "Forms!frmJobs!Cust")
> Me.ClientName = strClient
>
> End Sub
>
> Can some one please point out my error?

Remove the quotes surrounding:

Forms!frmJobs!Cust

otherwise VBA will interpret that as a literal string, ie:

F - o - r - m - s - ! - f - r - m etc.


From: Micki on
Unfortuantely, that doesn't work either. The debug error I'm getting is

Run-time error '3075':
Syntax error (missing operator) in query expression
'CustomerFromtblCustomersWHERECustomerID='.

Further help would be greatly appreciated.

"Micki" wrote:

> I am trying for a simple way to have an unbound control auto-filled based on
> another field on the form. I keep getting a syntax error no matter how I
> have manipluated my OpenRecordSet statement. Currently, I have
>
> Private Sub Form_Current()
> Dim strClient As DAO.Recordset
>
> Set strClient = CurrentDb.OpenRecordset ("SELECT Customer" & "FROM
> tblCustomers" & "WHERE CustomerID=" & "Forms!frmJobs!Cust")
> Me.ClientName = strClient
>
> End Sub
>
> Can some one please point out my error?
From: Ron Weiner on
Your are missing a bunch of spaces in your sql statement Change...

"SELECT Customer" & "FROM tblCustomers" & "WHERE CustomerID=" &
"Forms!frmJobs!Cust"

To

"SELECT Customer FROM tblCustomers WHERE CustomerID=" & Forms!frmJobs!Cust

Rdub


"Micki" <Micki(a)discussions.microsoft.com> wrote in message
news:8C6356C9-F419-4536-AB78-00A18EDDF4CD(a)microsoft.com...
> Unfortuantely, that doesn't work either. The debug error I'm getting is
>
> Run-time error '3075':
> Syntax error (missing operator) in query expression
> 'CustomerFromtblCustomersWHERECustomerID='.
>
> Further help would be greatly appreciated.
>
> "Micki" wrote:
>
>> I am trying for a simple way to have an unbound control auto-filled based
>> on
>> another field on the form. I keep getting a syntax error no matter how I
>> have manipluated my OpenRecordSet statement. Currently, I have
>>
>> Private Sub Form_Current()
>> Dim strClient As DAO.Recordset
>>
>> Set strClient = CurrentDb.OpenRecordset ("SELECT Customer" & "FROM
>> tblCustomers" & "WHERE CustomerID=" & "Forms!frmJobs!Cust")
>> Me.ClientName = strClient
>>
>> End Sub
>>
>> Can some one please point out my error?


From: Micki on
No, I have spaces in the VBA (see below); it's just that the debug message
runs everything together. I tried your quotes configuration as well & I'm
still getting a missing operator error.

"Ron Weiner" wrote:

> Your are missing a bunch of spaces in your sql statement Change...
>
> "SELECT Customer" & "FROM tblCustomers" & "WHERE CustomerID=" &
> "Forms!frmJobs!Cust"
>
> To
>
> "SELECT Customer FROM tblCustomers WHERE CustomerID=" & Forms!frmJobs!Cust
>
> Rdub
>
>
> "Micki" <Micki(a)discussions.microsoft.com> wrote in message
> news:8C6356C9-F419-4536-AB78-00A18EDDF4CD(a)microsoft.com...
> > Unfortuantely, that doesn't work either. The debug error I'm getting is
> >
> > Run-time error '3075':
> > Syntax error (missing operator) in query expression
> > 'CustomerFromtblCustomersWHERECustomerID='.
> >
> > Further help would be greatly appreciated.
> >
> > "Micki" wrote:
> >
> >> I am trying for a simple way to have an unbound control auto-filled based
> >> on
> >> another field on the form. I keep getting a syntax error no matter how I
> >> have manipluated my OpenRecordSet statement. Currently, I have
> >>
> >> Private Sub Form_Current()
> >> Dim strClient As DAO.Recordset
> >>
> >> Set strClient = CurrentDb.OpenRecordset ("SELECT Customer" & "FROM
> >> tblCustomers" & "WHERE CustomerID=" & "Forms!frmJobs!Cust")
> >> Me.ClientName = strClient
> >>
> >> End Sub
> >>
> >> Can some one please point out my error?
>
>
> .
>