Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2006, 01:09 PM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select Statement Help!!! PLEASE!!! Long Search

I am new to using VBA w/ Access, At anyrate I am trying to Have the user enter in a Quote Number (txtQuoteNumber) I labled it on the form. I am trying to take that value, and search a table(QuoteTable) to see if it is = to Quote_Number in my QuoteTable. If it is I want to extract The Dealer_Number so basically I want If txtQuoteNumber = QuoteTable[Quote_Number] Then QuoteTable[Dealer_Number] = txtDealerNumber.text

All of this code I have embedded into a Command Button using the Code builder I am using VB6 As well.

Basically the end result that I am trying to accomplish is that I want to be able to Autofill in some text boxes to make the form a lot easier. Any help would be appreciated a ton. I need to know how this would be done.
 
Old December 11th, 2006, 02:37 PM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There has to be an easy way to do this. Can anyone HELP PLEASE!!!!

 
Old December 11th, 2006, 03:27 PM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dim QuoteNumber As String
Dim strSQL As String
QuoteNumber = Me.txtQuoteNumber

DoCmd.OpenTable ("Quote Table")

strSQL = "SELECT Dealer_Number FROM Quote Table WHERE Quote_Number = '" & QuoteNumber & "'"

This so far seems to be working. It will open the table but I can not tell if it is Taking the Dealer_Number field and if so. How could i Possibly post it back into a text box on my current form and hide the table.

 
Old December 11th, 2006, 10:35 PM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to GolferGuy
Default

txtDealerNumber = DLookup("Dealer_Number", "QuoteTable", "Quote_Number=" & txtQuoteNumber)
This line of code will look in table "QuoteTable" in the "Quote_Number" field for a match to field "txtQuoteNumber" from your form. If that "txtQuoteNumber" is found, then the matching "Dealer_Number" will be written into "txtDealerNumber" on the form.
Hope this helps,

Vic
 
Old December 12th, 2006, 08:59 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Amazing! thanks vic works like a charm!

 
Old December 12th, 2006, 09:50 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Apparently you can not do 2 DLookup functions at a time?? I have these trying to run back to back to fill out more information
Me.txtDealerNumber = DLookup("Dealer_Number", "Quote Table", "Quote_Number=" & txtQuoteNumber)
Me.txtCustomerName = DLookup("Dealer_Name", "Dealers Table", "Dealer_Number=" & txtDealerNumber)

Im trying to autopopulate
DealerName
Dealer Address
Dealer City
Dealer State
Dealer zip
Dealer phone
Dealer Contact

All refrenced off of the Dealer Number that I had retrieved from the last DLookup

Any suggestions?

 
Old December 12th, 2006, 11:34 AM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to GolferGuy
Default

When you say "Apparently..." I assume you have tried this code that you have shown and it does not work. If that is the case, it is most helpful to show what the error message is that you received, or what the actual outcome of running the code is. Much easier to help when we know what the situation really is.

I'm going to suggest that the Dealer_Number could be a text field, rather than defined in the table as a Number. If that is the case, then you will need single quotes around the number when it is used in the Criteria parameter of the DLookup. To put the single quotes around the Dealer_Number the criteria code would look like this:
   ..., "Dealer_Number='" & txtDealerNumber & "'")

If that is not the situation, then post back with what is actually happening when you run the code you already showed us.
Vic

Vic
 
Old December 12th, 2006, 02:04 PM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again vic. I actually Had to put quotation marks around the last field in each statement to delimit it. ... "Quote_Number=" & "txtQuoteNumber" works like a charm now.

Thanks for the help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
select statement help... RinoDM SQL Server 2000 13 January 10th, 2008 08:34 PM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Select Statement jmss66 VB How-To 3 March 13th, 2006 03:55 PM
Select statement dungey PHP Databases 4 December 14th, 2004 04:08 PM
Select Statement jmss66 Oracle 1 May 27th, 2004 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.