Results 1 to 3 of 3
  1. #1
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21

    Fields function doesn't work for primary key/null field

    I wrote a function to return some field values from radio_variant table



    it worked fine if i only tried to get rec.Fields("radio_variant_title_tx")
    however, it got errors when i tried to do
    rec.Fields("radio_variant_id_cd")
    rec.Fields("note_tx")

    radio_variant_title_tx is a text field that will never be null
    radio_variant_id_cd is the primary key of the table
    note_tx is a text field that doesn't necessarily have a value

    1. so it seems to me that i can't get primary value and null field,
    but i believe there must be some way to retrieve the primary key field value and field that might contain null. if so, how?

    2. also, what will be the syntax in this case to get values from a lookup column? rec.Fields("[Lookup Column]")?

    thank you in advance


    Public Function getFields()

    Dim rec As Recordset
    Set rec = CurrentDb.OpenRecordset("select rv.* " + "from radio_variant rv", Type:=dbOpenDynaset)

    Dim output As String

    While Not rec.EOF
    output = output + rec.Fields("radio_variant_title_tx") + vbTab + rec.Fields("radio_variant_id_cd") + vbCrLf

    rec.MoveNext
    Wend

    MsgBox output, vbInformation, "test"

    rec.Close


    End Function

  2. #2
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21
    i got the part that a field may contain a null value figured out. not sure if there is a better way, but IsNull function seems to work.

    still got problems on using Fields or other vba function to get primary key value and Lookup column value

    anyone who can help, please?

  3. #3
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21
    i got it all figured out. i was trying to append numbers to a string without converting them 1st.

    sorry to bother and thanks

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

Similar Threads

  1. Replies: 3
    Last Post: 10-11-2011, 01:43 PM
  2. Replies: 1
    Last Post: 08-03-2010, 01:33 PM
  3. Can't get NZ Function to Work
    By Xiaoding in forum Queries
    Replies: 6
    Last Post: 04-14-2010, 09:54 AM
  4. Replies: 5
    Last Post: 03-20-2010, 08:30 AM
  5. Replies: 6
    Last Post: 02-19-2010, 03:52 PM

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