Results 1 to 14 of 14
  1. #1
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149

    cannot show combobox column value

    In a form, it has a combobox SelectCustomer and a button btnPrint.


    After selecting a customer from the combobox, the SelectCustomer_AfterUpdate sub can display Me.SelectCustomer.Column(1) correctly.
    But then I click the Print button, it shows the Me.SelectCustomer.Column(1) as null value.

    Code:
    Private Sub Form_Open()
    	With Me.SelectCustomer
    		.ColumnCount = 2
    		.RowSource = "SELECT CustNo,CustId FROM Customer ORDER BY CustNo"
    		.Value = ""
    	End With
    End Sub
    
    
    Private Sub SelectCustomer_AfterUpdate()
        MsgBox(Me.SelectCustomer.Column(1), vbOKOnly)
    End Sub
    
    
    Private Sub btnPrint_Click()
        MsgBox(Me.SelectCustomer.Column(1), vbOKOnly)
        ProcessReport "Printer"
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Are you printing the form? What is code in ProcessReport?

    Is this combobox UNBOUND? Why code in Open event to set combobox properties?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    not printing the form.
    ProcessReport retrieves data and print to printer.
    combobox is unbound.
    Code in Form_Open is setup the combobox for user to select customer.

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Why though, that makes no sense. Just permanently set the rowsource and column numbers in the design view of the form?
    It doesn't matter that it's unbound.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Understood ProcessReport sends something to printer but what and how? What is the code?

    Why annoy user with two popup messages that just tell them what they can see in combobox?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    The 2 popup messages are for debug purpose to see what value of Me.SelectCustomer.Column(1).
    The problem is after selecting a CustNo from the combobox, the
    Me.SelectCustomer.Column(1) has correct CustId value.
    Then click the Preview button, the
    Me.SelectCustomer.Column(1) becomes NULL value.
    The ProcessReport will use
    Me.SelectCustomer.Column(1) to retrieve data for printing.

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Try adding the red line to see if the rowsource has been changed. If so, scan you code to see why.
    Also, remove the first and last parens around the original messagebox line. The parens make it a function that wants to return a value, not to just display the message. I don't understand why you don't get a syntax error with that format!


    Private Sub btnPrint_Click()
    MsgBox Me.SelectCustomer.rowsource
    MsgBox(Me.SelectCustomer.Column(1), vbOKOnly)
    ProcessReport "Printer"
    End Sub

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I certainly get error with the parens.

    I don't see anything that would cause combobox to lose value.

    Is Preview button the btnPrint?

    Could provide db for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I don't see anything that would cause combobox to lose value.


    I agree. But I think we are not being given the whole picture, like the code shown is taken out of context.
    Need more from OP to provide meaningful help.

  10. #10
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    I add msgbox to see the rowsource (the red line) as suggested.

    Private Sub btnPrint_Click()
    MsgBox Me.SelectCustomer.rowsource
    MsgBox(Me.SelectCustomer.Column(1), vbOKOnly)
    ProcessReport "Printer"
    End Sub

    The msgbox shows correct rowsource.
    The second msgbox shows the Column(1) as null.

    It is so strange!
    After select a value from the combobox, then click the Print button, no other coding is
    executed.
    The combobox's AfterUpdate can show correct value of Column(1).
    But the button's Click cannot show it, even the rowsource still the same.





  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by uoghk View Post
    I add msgbox to see the rowsource (the red line) as suggested.

    Private Sub btnPrint_Click()
    MsgBox Me.SelectCustomer.rowsource
    MsgBox(Me.SelectCustomer.Column(1), vbOKOnly)
    ProcessReport "Printer"
    End Sub

    The msgbox shows correct rowsource.
    The second msgbox shows the Column(1) as null.

    It is so strange!
    After select a value from the combobox, then click the Print button, no other coding is
    executed.
    The combobox's AfterUpdate can show correct value of Column(1).
    But the button's Click cannot show it, even the rowsource still the same.

    Did you remove the extra parentheses from the MsgBox? (both of them)

    Msgbox Me.SelectCustomer.Column(1), vbokonly

  12. #12
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    I have not remove the parentheses from the MsgBox.
    But I run the code in debug mode and use the Watch window to see the value of Me.SelectCustomer.Column(1) and it is NULL.
    The problem is why the Column(1) becomes NULL value.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Again, suggest you provide db for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Here is the result of a setup the same as yours.


    Code:
    Private Sub cmdCheck_Click()
    Debug.Print Me.Combo3.RowSource
    Debug.Print Me.Combo3.Column(1)
    
    
    End Sub

    The first output is with nothing selected in the combo.
    The second with something selected in the combo. ?


    SELECT [Transactions].[ID], [Transactions].[Description] FROM Transactions ORDER BY [Description];
    Null


    SELECT [Transactions].[ID], [Transactions].[Description] FROM Transactions ORDER BY [Description];
    Miss B.Allen:157856
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 5
    Last Post: 03-09-2020, 10:10 AM
  2. Replies: 2
    Last Post: 04-09-2016, 01:23 PM
  3. Show multiple column's date in one column.
    By Littlewood in forum Access
    Replies: 2
    Last Post: 10-26-2015, 09:53 AM
  4. Replies: 3
    Last Post: 03-02-2015, 09:50 AM
  5. Replies: 1
    Last Post: 01-16-2015, 09:28 AM

Tags for this Thread

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