Default Values based on Value in another Table

A

Alberto

Here's what I need to do:
Prompt the user to enter a ModelID in TextBox1 and have the ModelRetailPrice
for that ModelID returned in TextBox2 - both the ModelID and ModelRetailPrice
are in Table1. Once the user does this they can enter data in TextBox3 and
TextBox4. I then want TextBox1, TextBox2, TextBox3 and TextBox4 to be stored
in Table 2. How do I do this?
 
A

Allen Browne

Use the AfterUpdate event procedure of Textbox1 to DLookup() the price of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order Details
subform, the ProductID combo has this kind of AfterUpdate event procedure to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
A

Alberto

Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost", "Table 1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in Criteria
Expression.
 
A

Alberto

I should also add that it says the following in the error message:
Run-time error: '3464'

Alberto said:
Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost", "Table 1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in Criteria
Expression.




Allen Browne said:
Use the AfterUpdate event procedure of Textbox1 to DLookup() the price of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order Details
subform, the ProductID combo has this kind of AfterUpdate event procedure to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
A

Allen Browne

Try breaking it down into steps, to see where the problem lies.

This kind of thing:

Dim strWhere As String
Dim varResult As Variant

If Not IsNull(Me.ModelID) Then
strWhere = "ModelID = "& Me.ModelID
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)
If Not IsNull(varResult) Then
Me.ModelRetailCost = varResult
End If
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Alberto said:
Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost", "Table 1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in Criteria
Expression.




Allen Browne said:
Use the AfterUpdate event procedure of Textbox1 to DLookup() the price of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order Details
subform, the ProductID combo has this kind of AfterUpdate event procedure
to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
 
A

Alberto

I still received the same error. This time in this line:
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)

I also tried doing it this way:

Private Sub ModelRetailPrice_AfterUpdate()
DLookup("ModelretailPrice","tblModel", "ModelID = '" &
Forms![frmQuotes]!ModelID & "'")
End Sub

but when I did, nothing happened.




Allen Browne said:
Try breaking it down into steps, to see where the problem lies.

This kind of thing:

Dim strWhere As String
Dim varResult As Variant

If Not IsNull(Me.ModelID) Then
strWhere = "ModelID = "& Me.ModelID
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)
If Not IsNull(varResult) Then
Me.ModelRetailCost = varResult
End If
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Alberto said:
Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost", "Table 1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in Criteria
Expression.




Allen Browne said:
Use the AfterUpdate event procedure of Textbox1 to DLookup() the price of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order Details
subform, the ProductID combo has this kind of AfterUpdate event procedure
to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html
Alberto said:
Here's what I need to do:
Prompt the user to enter a ModelID in TextBox1 and have the
ModelRetailPrice
for that ModelID returned in TextBox2 - both the ModelID and
ModelRetailPrice
are in Table1. Once the user does this they can enter data in TextBox3
and
TextBox4. I then want TextBox1, TextBox2, TextBox3 and TextBox4 to be
stored
in Table 2. How do I do this?
 
A

Allen Browne

So if yuo open your table in desigtn view, what Type is ModelID?

If it is Text (not Number), you need extra quotes:
strWhere = "ModelID = """ & Me.ModelID & """"

Explanation:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Alberto said:
I still received the same error. This time in this line:
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)

I also tried doing it this way:

Private Sub ModelRetailPrice_AfterUpdate()
DLookup("ModelretailPrice","tblModel", "ModelID = '" &
Forms![frmQuotes]!ModelID & "'")
End Sub

but when I did, nothing happened.




Allen Browne said:
Try breaking it down into steps, to see where the problem lies.

This kind of thing:

Dim strWhere As String
Dim varResult As Variant

If Not IsNull(Me.ModelID) Then
strWhere = "ModelID = "& Me.ModelID
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)
If Not IsNull(varResult) Then
Me.ModelRetailCost = varResult
End If
End If

Alberto said:
Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost", "Table
1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in
Criteria
Expression.




:

Use the AfterUpdate event procedure of Textbox1 to DLookup() the price
of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order
Details
subform, the ProductID combo has this kind of AfterUpdate event
procedure
to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

Here's what I need to do:
Prompt the user to enter a ModelID in TextBox1 and have the
ModelRetailPrice
for that ModelID returned in TextBox2 - both the ModelID and
ModelRetailPrice
are in Table1. Once the user does this they can enter data in
TextBox3
and
TextBox4. I then want TextBox1, TextBox2, TextBox3 and TextBox4 to
be
stored
in Table 2. How do I do this?
 
A

Alberto

Now when I click on ModelID in the Form, nothing happens. It's as if there
were no code. I don't get an error but I can go on to the rest of the form
and make other changes.

Allen Browne said:
So if yuo open your table in desigtn view, what Type is ModelID?

If it is Text (not Number), you need extra quotes:
strWhere = "ModelID = """ & Me.ModelID & """"

Explanation:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Alberto said:
I still received the same error. This time in this line:
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)

I also tried doing it this way:

Private Sub ModelRetailPrice_AfterUpdate()
DLookup("ModelretailPrice","tblModel", "ModelID = '" &
Forms![frmQuotes]!ModelID & "'")
End Sub

but when I did, nothing happened.




Allen Browne said:
Try breaking it down into steps, to see where the problem lies.

This kind of thing:

Dim strWhere As String
Dim varResult As Variant

If Not IsNull(Me.ModelID) Then
strWhere = "ModelID = "& Me.ModelID
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)
If Not IsNull(varResult) Then
Me.ModelRetailCost = varResult
End If
End If

Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost", "Table
1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in
Criteria
Expression.




:

Use the AfterUpdate event procedure of Textbox1 to DLookup() the price
of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order
Details
subform, the ProductID combo has this kind of AfterUpdate event
procedure
to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

Here's what I need to do:
Prompt the user to enter a ModelID in TextBox1 and have the
ModelRetailPrice
for that ModelID returned in TextBox2 - both the ModelID and
ModelRetailPrice
are in Table1. Once the user does this they can enter data in
TextBox3
and
TextBox4. I then want TextBox1, TextBox2, TextBox3 and TextBox4 to
be
stored
in Table 2. How do I do this?
 
A

Allen Browne

Temporarily include the line:
Stop
after the strWhere = ... but before the DLookup().

When it stops, open the Immediate Window (Ctrl+G), and examine what's going
on.
--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Alberto said:
Now when I click on ModelID in the Form, nothing happens. It's as if
there
were no code. I don't get an error but I can go on to the rest of the
form
and make other changes.

Allen Browne said:
So if yuo open your table in desigtn view, what Type is ModelID?

If it is Text (not Number), you need extra quotes:
strWhere = "ModelID = """ & Me.ModelID & """"

Explanation:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

Alberto said:
I still received the same error. This time in this line:
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)

I also tried doing it this way:

Private Sub ModelRetailPrice_AfterUpdate()
DLookup("ModelretailPrice","tblModel", "ModelID = '" &
Forms![frmQuotes]!ModelID & "'")
End Sub

but when I did, nothing happened.




:

Try breaking it down into steps, to see where the problem lies.

This kind of thing:

Dim strWhere As String
Dim varResult As Variant

If Not IsNull(Me.ModelID) Then
strWhere = "ModelID = "& Me.ModelID
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)
If Not IsNull(varResult) Then
Me.ModelRetailCost = varResult
End If
End If

Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost",
"Table
1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in
Criteria
Expression.




:

Use the AfterUpdate event procedure of Textbox1 to DLookup() the
price
of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order
Details
subform, the ProductID combo has this kind of AfterUpdate event
procedure
to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

Here's what I need to do:
Prompt the user to enter a ModelID in TextBox1 and have the
ModelRetailPrice
for that ModelID returned in TextBox2 - both the ModelID and
ModelRetailPrice
are in Table1. Once the user does this they can enter data in
TextBox3
and
TextBox4. I then want TextBox1, TextBox2, TextBox3 and TextBox4
to
be
stored
in Table 2. How do I do this
 
A

Alberto

I figured it out. I was pointing to the Model field which was a text instead
of pointing to the ModelID which was a number field. Thanks for your help.

Allen Browne said:
So if yuo open your table in desigtn view, what Type is ModelID?

If it is Text (not Number), you need extra quotes:
strWhere = "ModelID = """ & Me.ModelID & """"

Explanation:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Alberto said:
I still received the same error. This time in this line:
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)

I also tried doing it this way:

Private Sub ModelRetailPrice_AfterUpdate()
DLookup("ModelretailPrice","tblModel", "ModelID = '" &
Forms![frmQuotes]!ModelID & "'")
End Sub

but when I did, nothing happened.




Allen Browne said:
Try breaking it down into steps, to see where the problem lies.

This kind of thing:

Dim strWhere As String
Dim varResult As Variant

If Not IsNull(Me.ModelID) Then
strWhere = "ModelID = "& Me.ModelID
varResult = DLookup("ModelRetailCost", "Table 1", strWhere)
If Not IsNull(varResult) Then
Me.ModelRetailCost = varResult
End If
End If

Thanks. I think I'm almost there.

I typed the following into my form:
Forms![frmQuotes]!ModelRetailCost = DLookup("ModelRetailCost", "Table
1",
"ModelID = " & Forms![frmQuotes]!ModelID)

When I ran this I got the following error: Data Type Mismatch in
Criteria
Expression.




:

Use the AfterUpdate event procedure of Textbox1 to DLookup() the price
of
the ModelID in Table2.

For an example, see the Northwind sample database. In the Order
Details
subform, the ProductID combo has this kind of AfterUpdate event
procedure
to
get the price each from the Products table.

If you need help with DLookup(), see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

Here's what I need to do:
Prompt the user to enter a ModelID in TextBox1 and have the
ModelRetailPrice
for that ModelID returned in TextBox2 - both the ModelID and
ModelRetailPrice
are in Table1. Once the user does this they can enter data in
TextBox3
and
TextBox4. I then want TextBox1, TextBox2, TextBox3 and TextBox4 to
be
stored
in Table 2. How do I do this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top