robiago
asked on
dlookup error
With objWord
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks( "Date").Se lect 'Date
.Selection.Text = (CStr(Forms!Quote!Dateofco ntact))
.ActiveDocument.Bookmarks( "CN").Sele ct 'Organisation Name
.Selection.Text = (CStr(DLookup("Organisatio n", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]")))
.ActiveDocument.Bookmarks( "CN1").Sel ect 'Organisation Name
.Selection.Text = (CStr(DLookup("Organisatio n", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]")))
.ActiveDocument.Bookmarks( "Price").S elect 'Price
.Selection.Text = (CStr(Forms![Quote]![Text1 16]))
If Forms![Quote]![quote_sub_q uote]![Pub licholiday s] = -1 Then
.ActiveDocument.Bookmarks( "ph").Sele ct 'Public Holidays
.Selection.Text = (CStr("inclusive"))
Else
.ActiveDocument.Bookmarks( "ph").Sele ct 'Public Holidays
.Selection.Text = (CStr("exclusive"))
End If
.ActiveDocument.Bookmarks( "SRB").Sel ect 'Standard Rubbish bags
.Selection.Text = (CStr(DLookup("Cost", "Materials", "[Material No] = 94")) * 100 * 1.5)
.ActiveDocument.Bookmarks( "DocN").Se lect 'Document Number
.Selection.Text = (CStr(Forms!Quote!Communic ationID))
.ActiveDocument.Bookmarks( "BL").Sele ct 'Standard Rubbish bags
.Selection.Text = (CStr(DLookup("Cost", "Materials", "[Material No] = 522")) * 100 * 1.5)
.ActiveDocument.Bookmarks( "DPW").Sel ect 'Days per week
.Selection.Text = (CStr(Forms![Quote]![quote _subSUB_su mhrs]![NoD ays]))
.ActiveDocument.Bookmarks( "Street1") .Select 'Street Address 1
.Selection.Text = (CStr(DLookup("Street", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]")))
.ActiveDocument.Bookmarks( "Street2") .Select 'Suburb
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = DLookup(Suburb, Organisation, OrganisationID = Forms![quote]![Organisatio nID])")))
Word.ActiveDocument.Active Window.Vie w.Type = wdPrintView
###
Im getting an error on this line:
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = DLookup(Suburb, Organisation, OrganisationID = Forms![quote]![Organisatio nID])")))
Error 2001
You cancelled the previous operation
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(Forms!Quote!Dateofco
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(DLookup("Organisatio
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(DLookup("Organisatio
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(Forms![Quote]![Text1
If Forms![Quote]![quote_sub_q
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr("inclusive"))
Else
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr("exclusive"))
End If
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(DLookup("Cost", "Materials", "[Material No] = 94")) * 100 * 1.5)
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(Forms!Quote!Communic
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(DLookup("Cost", "Materials", "[Material No] = 522")) * 100 * 1.5)
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(Forms![Quote]![quote
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(DLookup("Street", "Organisation", "OrganisationID = Forms![quote]![Organisatio
.ActiveDocument.Bookmarks(
.Selection.Text = (CStr(DLookup("Description
Word.ActiveDocument.Active
###
Im getting an error on this line:
.Selection.Text = (CStr(DLookup("Description
Error 2001
You cancelled the previous operation
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = " & DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]))
Is this lookup returning as value compatible with ID (are they both numbers)?
They have to be same. If they are string use:
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = " & chr(34) & DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]) & chr(34))
MIke
Is this lookup returning as value compatible with ID (are they both numbers)?
They have to be same. If they are string use:
.Selection.Text = (CStr(DLookup("Description
MIke
ASKER
hey Walt
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = 9")))
works
When I try:
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]")")))
it gives me a syntax error on suburb says it expects a list seperator or )
I dont see why I would need &
Rob
.Selection.Text = (CStr(DLookup("Description
works
When I try:
.Selection.Text = (CStr(DLookup("Description
it gives me a syntax error on suburb says it expects a list seperator or )
I dont see why I would need &
Rob
That's just the way it works. I'd suggest getting the second piece working before trying to combine them.
Here a recent example related to your problem:
https://www.experts-exchange.com/questions/20791855/DLookup-Question.html
Walt
Here a recent example related to your problem:
https://www.experts-exchange.com/questions/20791855/DLookup-Question.html
Walt
try:
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = " & DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]))
if Suburb is a number. See my last post for more...
Mike
.Selection.Text = (CStr(DLookup("Description
if Suburb is a number. See my last post for more...
Mike
ASKER
hey Mike,
I tried that and it gave me the same error: expects a list seperator or )
but it didnt highlight anything and yes suburb is a number
I'll double check they are both the same
Rob
I tried that and it gave me the same error: expects a list seperator or )
but it didnt highlight anything and yes suburb is a number
I'll double check they are both the same
Rob
You never veryfied whether ID and Suburb have the same property or not. Do they have same property?
Try:
.Selection.Text = CStr(DLookup("Description" , "Types", "[ID] = " & DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]))
Try:
.Selection.Text = CStr(DLookup("Description"
Mike
So you know
Your code is missing a " at the end. You only have 11 total.
Thought I'd could help
Walt
So you know
Your code is missing a " at the end. You only have 11 total.
Thought I'd could help
Walt
ASKER
they do have the same property, suburb looks up ID in types
ASKER
same error mike
Thanks walt.
--------
To paly safe, lets try this first.
---------------code starts here
Dim IdVar
MsgBox "1: VarType= " & Vartype(Forms![quote]![Org anisationI D]) "; " & Forms![quote]![Organisatio nID]
IdVar =DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]
MsgBox "2: VarType= " & Vartype(IdVar) "; " & IdVar
.Selection.Text = CStr(DLookup("Description" , "Types", "[ID] = " & IdVar)
---------------code ends here
let me know, using above code, what you get for msgbox 1 and 2.
Mike
--------
To paly safe, lets try this first.
---------------code starts here
Dim IdVar
MsgBox "1: VarType= " & Vartype(Forms![quote]![Org
IdVar =DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio
MsgBox "2: VarType= " & Vartype(IdVar) "; " & IdVar
.Selection.Text = CStr(DLookup("Description"
---------------code ends here
let me know, using above code, what you get for msgbox 1 and 2.
Mike
ASKER
sorry mike i wasnt born a coder :/
it says syntax error on these lines:
MsgBox "1: VarType= " & Vartype(Forms![quote]![Org anisationI D]) "; " & Forms![quote]![Organisatio nID]
IdVar =DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]
MsgBox "2: VarType= " & Vartype(IdVar) "; " & IdVar
.Selection.Text = CStr(DLookup("Description" , "Types", "[ID] = " & IdVar)
Rob
it says syntax error on these lines:
MsgBox "1: VarType= " & Vartype(Forms![quote]![Org
IdVar =DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio
MsgBox "2: VarType= " & Vartype(IdVar) "; " & IdVar
.Selection.Text = CStr(DLookup("Description"
Rob
Mike
I'm curious why your 2 strands are different styles:
dlookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]")
DLookup("Description", "Types", "[ID] = " & IdVar)
see the difference?
One has " and &
one doesn't
Personally I think this is the problem.
Walt
I'm curious why your 2 strands are different styles:
dlookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio
DLookup("Description", "Types", "[ID] = " & IdVar)
see the difference?
One has " and &
one doesn't
Personally I think this is the problem.
Walt
Try Mike's lines this way:
MsgBox "1: VarType= " & Vartype(Forms![quote]![Org anisationI D]) & "; " & Forms![quote]![Organisatio nID]
IdVar =DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]")
MsgBox "2: VarType= " & Vartype(IdVar) & "; " & IdVar
Just missing a quote or and & here and there. It happens.
MsgBox "1: VarType= " & Vartype(Forms![quote]![Org
IdVar =DLookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio
MsgBox "2: VarType= " & Vartype(IdVar) & "; " & IdVar
Just missing a quote or and & here and there. It happens.
Hi Rob,
I suspect code can't read OrganisationID from your form. To check that, try follwing instead:
MsgBox "1: VarType= " & nz(Forms![quote]![Organisa tionID],"c an't read OrganisationID")
------
Hi Walt,
we can write:
dlookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio nID]") or
dlookup("Suburb", "Organisation", "OrganisationID =" & Forms![quote]![Organisatio nID])
they both will work, but we don't have that option with:
DLookup("Description", "Types", "[ID] = " & IdVar)
Mike
I suspect code can't read OrganisationID from your form. To check that, try follwing instead:
MsgBox "1: VarType= " & nz(Forms![quote]![Organisa
------
Hi Walt,
we can write:
dlookup("Suburb", "Organisation", "OrganisationID = Forms![quote]![Organisatio
dlookup("Suburb", "Organisation", "OrganisationID =" & Forms![quote]![Organisatio
they both will work, but we don't have that option with:
DLookup("Description", "Types", "[ID] = " & IdVar)
Mike
ASKER
it came back:
1: Vartype = 3; 12
2: Vartype = 3; 17
1: Vartype = 3; 12
2: Vartype = 3; 17
Rob,
It gave you the error because after update of OrganisationID wasn't fired and couldn't get its value (I suspect). If this happens again, we need to handle it somehow.
Do you the solution now?
Mike
It gave you the error because after update of OrganisationID wasn't fired and couldn't get its value (I suspect). If this happens again, we need to handle it somehow.
Do you the solution now?
Mike
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK:
OrganisationID = Forms![quote]![Organisatio nID]
the first organisation ID is located in the Organisation table the second is located in the form quote
which one is the problem?
OrganisationID = Forms![quote]![Organisatio
the first organisation ID is located in the Organisation table the second is located in the form quote
which one is the problem?
The one you have (or enter data into), OrganisationID on form quote.
Forms![quote]![Organisatio nID]
I don't know what table it is linked to. BTW, is it is linke, it shouldn't problem unluss it is a new data entry (new record) and OrganisationID value is not there yet.
Is text box Forms![quote]![Organisatio nID] unbound?
Mike
Forms![quote]![Organisatio
I don't know what table it is linked to. BTW, is it is linke, it shouldn't problem unluss it is a new data entry (new record) and OrganisationID value is not there yet.
Is text box Forms![quote]![Organisatio
Mike
ASKER
its linked to the organisation table
SELECT Organisation.OrganisationI D, Organisation.Organisation FROM Organisation;
SELECT Organisation.OrganisationI
What kind of proble you are having as is stands. For now, keep follwing line active until you are sure it doesn't return null values for OrganisationID:
MsgBox "1: VarType= " & nz(Forms![quote]![Organisa tionID],"c an't read OrganisationID")
Mike
MsgBox "1: VarType= " & nz(Forms![quote]![Organisa
Mike
ASKER
I think the problem is that I have a table called Quote and a form called quote and that its seeing Forms! as a field and not as something telling it to please look @ forms - quote - org id
For your future consideration:
Quote
for table call it tQuote
for form call it fQoute
for subform call it sfQoute
for query call it qQoute
Primary keys call it CustID
Foreing Keys call it Cust_ID
------------
As far as your recent question is concerend, past the portion of the code is doing that.
Mike
Quote
for table call it tQuote
for form call it fQoute
for subform call it sfQoute
for query call it qQoute
Primary keys call it CustID
Foreing Keys call it Cust_ID
------------
As far as your recent question is concerend, past the portion of the code is doing that.
Mike
ASKER
thanks mike :D
ASKER
I tried:
MsgBox "1: VarType= " & nz(Forms![quote]![Organisa tionID],"c an't read OrganisationID")
came back with Vartype = 12
MsgBox "1: VarType= " & nz(Forms![quote]![Organisa
came back with Vartype = 12
My bad, use:
MsgBox "Current value of OrganisationID is: " & nz(Forms![quote]![Organisa tionID],"c an't read OrganisationID") & " remove this message box after number of successful test."
MsgBox "Current value of OrganisationID is: " & nz(Forms![quote]![Organisa
ASKER
OK the msg box was working and Ive removed it
.Selection.Text = (CStr(DLookup("Description ", "Types", "[ID] = & DLookup(Suburb, Organisation, OrganisationID = Forms![quote]![Organisatio nID])")))
I've taken the " " out of the last dlookup because it kept giving me an error: expects a list seperator or )
and as it is now I get this error:
3075:
syntax error (missing operator) in query expression 'ID = & DLookup(Suburb, Organisation, OrganisationID = Forms![quote]![Organisatio nID])'.
.Selection.Text = (CStr(DLookup("Description
I've taken the " " out of the last dlookup because it kept giving me an error: expects a list seperator or )
and as it is now I get this error:
3075:
syntax error (missing operator) in query expression 'ID = & DLookup(Suburb, Organisation, OrganisationID = Forms![quote]![Organisatio
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that worked! :D mint thanks so much
(CStr(DLookup("Description
Does it work?
I can see this piece is broken
DLookup(Suburb, Organisation, OrganisationID = Forms![quote]![Organisatio
DLookup("Suburb", "Organisation", "[OrganisationID] = " & Forms![quote]![Organisatio
I suggest getting it working too THEN you can combine them into something like:
CStr(DLookup("Description"
Good luck
Walt