Results 1 to 4 of 4
  1. #1
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    Help creating a VBA recordset, Pulling the data I need into it, and placing them in VBA variables.

    Backend Sql Server 2008, front end access 2007.

    I have a page of VBA code which creates a new record using a SQL Insert Into statement writing to the underlying dbo_PropertyYearDetail table. The Sql query works fine. But now I need to add 7 fields from another SQL table called dbo_FeeScheduleLookup table. I then need to pull the 7 values from the Lookup table into my VBA page as 7 variables. Then I can edit them into the SQL Insert Into statement and append everything at one time.



    I think this can be achieved by creating a recordset in VBA and pulling the field values from the Lookup Table into variables. The only part I need help with is creating the recordset to pull the 7 fields and assign them to variables. The 7 fields contain percentages if that makes any difference.

    I've read everything I can find and I'm just not getting it. Can someone show me some sample code that might work?

    Thanks

    Fred

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    YOu can use Alter Table to add the columns in a table.

    You could pull the related data for a variable using dlookup for one variable. Sample code
    Code:
    dim strVar as string
    strVar=nz(dlookup("fieldname","tablename", "[fieldapples]='apples'"),"")

  3. #3
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    Hi and thanks. Two questions:

    I understand the strVar=nz(dlookup("fieldname","tablename", (But I don't understand the apples part)--> "[fieldapples]='apples'"),"") What is this part doing?

    Also as it is writing to a SQL 2008 table with Field Type = Decimal (2.2) Percentage should I have the variable dimmed as Long instead of string?

    I think the dlookup is the best route.

    I don't understand how Alter Table works but I will look it up.

    Thanks I appreciate your help.

    Fred

  4. #4
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    I got it, thanks. Appreciate the help. I will mark this closed.

    Fred

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Placing query data on the form
    By snowboarder234 in forum Forms
    Replies: 7
    Last Post: 11-07-2012, 11:30 AM
  2. creating recordset based on query
    By akrylik in forum Access
    Replies: 8
    Last Post: 05-10-2012, 02:57 PM
  3. Replies: 1
    Last Post: 11-13-2009, 03:03 AM
  4. VBA Opening Excel File and Placing Data in Cells
    By BobTHG in forum Programming
    Replies: 0
    Last Post: 01-13-2008, 03:01 PM
  5. Placing '0' in front of data
    By wasim_sono in forum Queries
    Replies: 2
    Last Post: 09-07-2006, 06:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums