Results 1 to 9 of 9
  1. #1
    mladen273 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    19

    VBA code for MsgBox

    Hi,


    I have a query called "q_skenirano".
    I have a field called "Broj naloga","barkod","skenirano".
    For now I want to know how to write VBA code, when the Broj naloga field is blank to throw me a message wrong barkod.

    I'm was writing;

    If IsNull [q_skenirano]![Broj naloga] Then
    MsgBox("krivi barkod")

    I get compile error:
    Expected: Then or GoTo

    Please can help me someone.

    B.R.

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Try this:

    Code:
    If IsNull ([q_skenirano]![Broj naloga]) Then
    MsgBox("krivi barkod")
    


    Add the Parens to the IsNull line as shown. Compile again.

  3. #3
    mladen273 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    19
    Code does not work.
    I get again error.

    In attach is picture with error.
    Attached Thumbnails Attached Thumbnails message.png  

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    I think that the syntax for calling the subform in the line of code
    Code:
    If [Forms]![F_provjera naloga]![_1 subform]![Napomena]
    is incorrect. The proper syntax would be
    me.YourSubformName.Form.MainFormName!YourControlNa me = "Visak" Then

    When you get the compile error is this the line that is highlighted in yellow?

    Look at this video on subforms http://www.datapigtechnologies.com/f.../subform2.html

    You should avoid using spaces in your naming conventions as it may cause you to have errors in the future remembering spacing while typing. I would urge you to use what is referred to as Camel Convention. For example: Your Form in this example would be fProvjeraNaloga

  5. #5
    mladen273 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    19
    Thanks for the answer, but for me this form is working.
    I have the problem with If IsNull [q_skenirano]![Broj naloga] Then
    MsgBox("krivi barkod").

    When VBA send error, tihs code is yellow.
    Can you help me with this?

  6. #6
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Wink If without end if

    Quote Originally Posted by mladen273 View Post
    Hi,
    I have a query called "q_skenirano".
    I have a field called "Broj naloga","barkod","skenirano".
    For now I want to know how to write VBA code, when the Broj naloga field is blank to throw me a message wrong barkod.

    I'm was writing;

    If IsNull [q_skenirano]![Broj naloga] Then
    MsgBox("krivi barkod")

    I get compile error:
    Expected: Then or GoTo

    Please can help me someone.

    B.R.
    If you use If statement without end IF must be a single line.
    Your error as shown indicates that there is confusion in naming fields hence the "[" in the error. Double check your field names. Hope this helps

  7. #7
    mladen273 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    19
    Quote Originally Posted by alansidman View Post
    I think that the syntax for calling the subform in the line of code
    Code:
    If [Forms]![F_provjera naloga]![_1 subform]![Napomena]
    is incorrect. The proper syntax would be
    me.YourSubformName.Form.MainFormName!YourControlNa me = "Visak" Then

    When you get the compile error is this the line that is highlighted in yellow?

    Look at this video on subforms http://www.datapigtechnologies.com/f.../subform2.html

    You should avoid using spaces in your naming conventions as it may cause you to have errors in the future remembering spacing while typing. I would urge you to use what is referred to as Camel Convention. For example: Your Form in this example would be fProvjeraNaloga
    Hi,
    I change this me.frmProvjera.Form.F_provjeraNaloga!Napomena = "Visak" Then MsgBox ("Višak") - but I have error
    run time '2465'
    Aplication-defined or object-defined error.

    Please can you help me

    B.R.

  8. #8
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    One of the ways is to use Domain aggregate functions (Dlookup,Dfirst,Dcount)
    Something like :
    Code:
    If DCount("Broj naloga","q_skenirano","[barkod]='" & Barkode & "'")=0 Then
    Msgbox " your message"
    EndIf

  9. #9
    stmoong is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2011
    Location
    Singapore
    Posts
    108
    If I understand correctly, you will need to open a recordset for the query "q_skenirano" where the field "Broj naloga" is Null.

    So, you will need to do something like this, add the Microsoft DAO Object library in the reference.

    Code:
        Dim db as DAO.Database
        Dim rs as DAO.Recordset
    
        Set db = CurrentDb
    
        '.....Existing code.....
        Set rs = db.OpenRecordset("SELECT * FROM q_skenirano WHERE [Broj naloga] Is Null", dbOpenSnapshot)
    
        If Not rs.EOF Then
            MsgBox "krivi barkod"
            '.....Existing code.....
        End If
    
        'Clean up code
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    However, I do not quite understand the logic of checking after you insert into the record into a table. Shouldn't you be checking before inserting the record to the table?

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

Similar Threads

  1. Cannot locate VBA code for MsgBox!
    By sjl in forum Forms
    Replies: 5
    Last Post: 12-20-2011, 05:26 PM
  2. Yes No msgbox
    By imintrouble in forum Access
    Replies: 3
    Last Post: 10-14-2011, 02:24 PM
  3. MsgBox after exporting
    By sk88 in forum Access
    Replies: 2
    Last Post: 08-26-2011, 06:50 AM
  4. MsgBox
    By Mtyetti in forum Forms
    Replies: 4
    Last Post: 07-27-2011, 01:51 PM
  5. Msgbox And Search Code Not Working Properly
    By vampyr07au in forum Forms
    Replies: 1
    Last Post: 05-02-2011, 05:16 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