PC Review


Reply
Thread Tools Rate Thread

Auto-populate form using Dlookup from multiple table fields

 
 
Leo S.
Guest
Posts: n/a
 
      25th Mar 2009
I have a form that I fill out that has 2 fields - PSN_Number &
Channel_Number. What I want to achieve is for another field to auto populate
with data from a 3rd field (Degraded_Serial_Number) which is dependant on
what is entered in the 2 fields above. I have a table that corresponds this
info - HDD_List. No matter what I have tried, I cannot get it to work.
Below is the code that I am using:

Private Sub Channel_Number_AfterUpdate()
On Error GoTo Err_Channel_Number_AfterUpdate

Dim strFilter As String

' Evaluate filter before it's passed to DLookup function.
strFilter = "Channel_Number = " & Me!Channel_Number

' Look up HDD Serial Number and assign it to Degraded Serial Number
control.
Me!Degraded_Serial_Number = DLookup("HDD_Serial_Number", "HDD_List",
strFilter)

Exit_Channel_Number_AfterUpdate:
Exit Sub

Err_Channel_Number_AfterUpdate:
MsgBox Err.Description
Resume Exit_Channel_Number_AfterUpdate

End Sub

Adding the criteria to the DLookup line is where I am lost. Hopefully
someone can point me in the right direction.

TIA
 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      25th Mar 2009
Hi,
are you getting an error? if Channel_Number is a text field then filter
should be (value in quotes):

strFilter = "Channel_Number = '" & Me!Channel_Number & "'"

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Leo S." <Leo S.@discussions.microsoft.com> wrote in message
news:F4FB61FF-C75C-4266-AC4B-(E-Mail Removed)...
> I have a form that I fill out that has 2 fields - PSN_Number &
> Channel_Number. What I want to achieve is for another field to auto
> populate
> with data from a 3rd field (Degraded_Serial_Number) which is dependant on
> what is entered in the 2 fields above. I have a table that corresponds
> this
> info - HDD_List. No matter what I have tried, I cannot get it to work.
> Below is the code that I am using:
>
> Private Sub Channel_Number_AfterUpdate()
> On Error GoTo Err_Channel_Number_AfterUpdate
>
> Dim strFilter As String
>
> ' Evaluate filter before it's passed to DLookup function.
> strFilter = "Channel_Number = " & Me!Channel_Number
>
> ' Look up HDD Serial Number and assign it to Degraded Serial Number
> control.
> Me!Degraded_Serial_Number = DLookup("HDD_Serial_Number", "HDD_List",
> strFilter)
>
> Exit_Channel_Number_AfterUpdate:
> Exit Sub
>
> Err_Channel_Number_AfterUpdate:
> MsgBox Err.Description
> Resume Exit_Channel_Number_AfterUpdate
>
> End Sub
>
> Adding the criteria to the DLookup line is where I am lost. Hopefully
> someone can point me in the right direction.
>
> TIA


 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      25th Mar 2009
Leo S. <Leo S.@discussions.microsoft.com> wrote:

>I have a form that I fill out that has 2 fields - PSN_Number &
>Channel_Number. What I want to achieve is for another field to auto populate
>with data from a 3rd field (Degraded_Serial_Number) which is dependant on
>what is entered in the 2 fields above. I have a table that corresponds this
>info - HDD_List. No matter what I have tried, I cannot get it to work.
>Below is the code that I am using:
>
>Private Sub Channel_Number_AfterUpdate()
>On Error GoTo Err_Channel_Number_AfterUpdate
>
> Dim strFilter As String
>
> ' Evaluate filter before it's passed to DLookup function.
> strFilter = "Channel_Number = " & Me!Channel_Number
>
> ' Look up HDD Serial Number and assign it to Degraded Serial Number
>control.
> Me!Degraded_Serial_Number = DLookup("HDD_Serial_Number", "HDD_List",
>strFilter)
>
>Exit_Channel_Number_AfterUpdate:
> Exit Sub
>
>Err_Channel_Number_AfterUpdate:
> MsgBox Err.Description
> Resume Exit_Channel_Number_AfterUpdate
>
>End Sub
>
>Adding the criteria to the DLookup line is where I am lost. Hopefully
>someone can point me in the right direction.



Depends on the data type of the fields in the criteria.
What you have should work for a number type Channel_Number
field.

Your code only uses the one field, but you said you wanted
to use two fields. Assuming the PSN_Number field is also a
number type field, try using:

strFilter = "Channel_Number = " & Me!Channel_Number _
& " AND PSN_Number = " & Me!PSN_Number

If both fields are Text fields, then that would beL

strFilter = "Channel_Number = """ & Me!Channel_Number _
& """ AND PSN_Number = """ & Me!PSN_Number & """"

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
Leo S.
Guest
Posts: n/a
 
      25th Mar 2009
Thank you for your help Alex. Not getting an error....mind you the code is
incomplete. I realize that my explanation below is a little unclear. Here
is what I have:

A form Named "Add_New_Incident" with the following fields:
"PSN_Number"
"Channel_Number"
"Degraded_Serial_Number" - this is the one I want to auto populate

I have a table called "HDD_List" which has 3 fields:
"PSN_Number"
"Channel_Number"
"HDD_Serial_Number" - this is where I want to get the data for the field
above from

So what I basically want , is when I input a PSN # and a Channel # in to my
form, it will go and look at the table and populate the
"Degraded_Serial_Number" field with the corresponding Serial Number.

Example - I enter PSN 5, Channel 7....HDD_List table shows the serial # as
123456.

LOL...I hope that makes it easy to understand.

Thanks again

"Alex Dybenko" wrote:

> Hi,
> are you getting an error? if Channel_Number is a text field then filter
> should be (value in quotes):
>
> strFilter = "Channel_Number = '" & Me!Channel_Number & "'"
>
> --
> Best regards,
> ___________
> Alex Dybenko (MVP)
> http://accessblog.net
> http://www.PointLtd.com
>
>
> "Leo S." <Leo S.@discussions.microsoft.com> wrote in message
> news:F4FB61FF-C75C-4266-AC4B-(E-Mail Removed)...
> > I have a form that I fill out that has 2 fields - PSN_Number &
> > Channel_Number. What I want to achieve is for another field to auto
> > populate
> > with data from a 3rd field (Degraded_Serial_Number) which is dependant on
> > what is entered in the 2 fields above. I have a table that corresponds
> > this
> > info - HDD_List. No matter what I have tried, I cannot get it to work.
> > Below is the code that I am using:
> >
> > Private Sub Channel_Number_AfterUpdate()
> > On Error GoTo Err_Channel_Number_AfterUpdate
> >
> > Dim strFilter As String
> >
> > ' Evaluate filter before it's passed to DLookup function.
> > strFilter = "Channel_Number = " & Me!Channel_Number
> >
> > ' Look up HDD Serial Number and assign it to Degraded Serial Number
> > control.
> > Me!Degraded_Serial_Number = DLookup("HDD_Serial_Number", "HDD_List",
> > strFilter)
> >
> > Exit_Channel_Number_AfterUpdate:
> > Exit Sub
> >
> > Err_Channel_Number_AfterUpdate:
> > MsgBox Err.Description
> > Resume Exit_Channel_Number_AfterUpdate
> >
> > End Sub
> >
> > Adding the criteria to the DLookup line is where I am lost. Hopefully
> > someone can point me in the right direction.
> >
> > TIA

>
>

 
Reply With Quote
 
Leo S.
Guest
Posts: n/a
 
      25th Mar 2009
Thanks very much Marshall. You're awesome. That was the fix I was looking
for.

"Marshall Barton" wrote:

> Leo S. <Leo S.@discussions.microsoft.com> wrote:
>
> >I have a form that I fill out that has 2 fields - PSN_Number &
> >Channel_Number. What I want to achieve is for another field to auto populate
> >with data from a 3rd field (Degraded_Serial_Number) which is dependant on
> >what is entered in the 2 fields above. I have a table that corresponds this
> >info - HDD_List. No matter what I have tried, I cannot get it to work.
> >Below is the code that I am using:
> >
> >Private Sub Channel_Number_AfterUpdate()
> >On Error GoTo Err_Channel_Number_AfterUpdate
> >
> > Dim strFilter As String
> >
> > ' Evaluate filter before it's passed to DLookup function.
> > strFilter = "Channel_Number = " & Me!Channel_Number
> >
> > ' Look up HDD Serial Number and assign it to Degraded Serial Number
> >control.
> > Me!Degraded_Serial_Number = DLookup("HDD_Serial_Number", "HDD_List",
> >strFilter)
> >
> >Exit_Channel_Number_AfterUpdate:
> > Exit Sub
> >
> >Err_Channel_Number_AfterUpdate:
> > MsgBox Err.Description
> > Resume Exit_Channel_Number_AfterUpdate
> >
> >End Sub
> >
> >Adding the criteria to the DLookup line is where I am lost. Hopefully
> >someone can point me in the right direction.

>
>
> Depends on the data type of the fields in the criteria.
> What you have should work for a number type Channel_Number
> field.
>
> Your code only uses the one field, but you said you wanted
> to use two fields. Assuming the PSN_Number field is also a
> number type field, try using:
>
> strFilter = "Channel_Number = " & Me!Channel_Number _
> & " AND PSN_Number = " & Me!PSN_Number
>
> If both fields are Text fields, then that would beL
>
> strFilter = "Channel_Number = """ & Me!Channel_Number _
> & """ AND PSN_Number = """ & Me!PSN_Number & """"
>
> --
> Marsh
> MVP [MS Access]
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto populate form fields from table =?Utf-8?B?RnJlZWZseWVy?= Microsoft Access Form Coding 4 20th Nov 2007 10:20 AM
Auto Populate Fields In Table =?Utf-8?B?V01vcnNiZXJnZXI=?= Microsoft Access 2 30th Oct 2006 04:23 PM
how to auto populate a field from another table using dlookup Ray Microsoft Access Form Coding 5 26th Jul 2004 12:18 AM
Dlookup using Multiple fields from a table chinaboy992 Microsoft Access Macros 1 1st Mar 2004 07:24 AM
Auto-populate multiple Fields Mike Microsoft Access VBA Modules 5 22nd Sep 2003 08:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:59 PM.