Results 1 to 2 of 2
  1. #1
    Lidwina is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2011
    Posts
    1

    Coloring a combobox as error message?!

    Hi



    I'm trying to make a form in wich, if you receive an article, you put it in a certain location. If there is already an article on that location, the combobox in wich you choose the location the combobox should color red. It doesn't mean the article can't be placed on that location but it should be checked.

    The combobox is filled with data from a tabel 'Locations' and the selected option should be checked in a query 'qryStock'.

    Code:
    Private Sub cboLocation_AfterUpdate()
    Dim rs0 As ADODB.Recordset
     
    'Set rs0 = CurrentDb.OpenRecordset("SELECT ArtikcleNr FROM qryStock WHERE LocationNr = '" & Me.cboLocatie.Text & "'") <-- Error 13 occurs here
     
    'rs0.Open "SELECT ArticleNr FROM qryStock WHERE LocationNr = '" & Me.cboLocation & "'", CurrentProject.OpenConnection, adOpenStatic, adLockReadOnly <-- Error 91 occurs here
     
    If rs0.RecordCount > 0 Then
    Me.cboLocation.BackColor = 255
    Me.cboLocation.ForeColor = 16777215
    Else
    Me.cboLocation.BackColor = 16777215
    Me.cboLocation.ForeColor = 0
    End If
    End Sub
    This is the code I have so far. I have tried 2 different options, both give an error.
    The first option gives the error 13: Type mismatch.
    The second option gives the error 91: Object variable or With block not set.

    I really hope you guys can help.

    With kind regards

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    What's the data type of LocationNr in the table? If it's numeric, you don't want the single quotes around the value. You're also using a different control name than in the sub header, which might be correct but if so you can't use the .Text property. You also seem to be mixing ADO and DAO syntax's.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Error message when importing
    By ljenkins23 in forum Access
    Replies: 5
    Last Post: 06-10-2010, 09:30 AM
  2. error message
    By ngeng4 in forum Forms
    Replies: 85
    Last Post: 03-25-2010, 06:47 AM
  3. where do i start with this error message?
    By Student4Life in forum Access
    Replies: 0
    Last Post: 01-09-2009, 04:12 PM
  4. FROM Clause error message
    By skylite in forum Queries
    Replies: 2
    Last Post: 10-23-2008, 05:47 AM
  5. If / Then Error Message
    By Schwagr in forum Forms
    Replies: 4
    Last Post: 03-30-2006, 06:28 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