Results 1 to 14 of 14
  1. #1
    suzana is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    May 2019
    Posts
    6

    run time error 3075 suntax error missing operatorb in query expression...

    hi...im newbie in access....straight to the point...i'm trying to create vba to prevent duplicate data entry from u tube...then its getting error like above
    and vba code as below:

    Private Sub Nama_AfterUpdate()
    Dim NewNama As String
    Dim stLinkCriteria As String
    Dim IDProduk As Integer
    NewNama = Me.Nama.Value
    stLinkCriteria = "(nama) = " & " " '" & NewNama & "'"
    If Me.Nama = DLookup("[nama]", "tblproduk", stLinkCriteria) Then
    MsgBox "Nama Spesis ini, " & NewNama & ", Telah wujud dalam Database." _
    & vbCr & vbCr & "Sila semak semula Nama Spesis...!", vbInformation, "Duplicate information"
    'Me.Undo


    End If
    IDProduk = DLookup("(Idproduk)", "tblproduk", stLinkCriteria)
    Me.DataEntry = False
    DoCamd.FindRecord IDProduk, , , , , acCurrent


    please everyone expert help me to sol this problem..

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    try changing this

    stLinkCriteria = "(nama) = " & " " '" & NewNama & "'"

    to this

    stLinkCriteria = "[nama] = '" & NewNama & "'"

    also dlookup will return null if a record is not found so suggest this

    If Me.Nama = DLookup("[nama]", "tblproduk", stLinkCriteria) Then

    should be

    If not isnull(DLookup("[nama]", "tblproduk", stLinkCriteria|)) Then 'name already exists

    or better

    If DCount("*", "tblproduk", stLinkCriteria) Then 'name already exists

  3. #3
    suzana is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    May 2019
    Posts
    6
    tq very much for your help sir...i did try your suggestion but it's stil stuck as below...


    Click image for larger version. 

Name:	debug.jpg 
Views:	20 
Size:	16.6 KB 
ID:	38541

    when i klik debug it's show

    Private Sub Nama_AfterUpdate()
    Dim NewNama As String
    Dim stLinkCriteria As String
    Dim IDProduk As Integer
    NewNama = Me.Nama.Value
    stLinkCriteria = "[nama] = '" & NewNama & "'"
    If DCount("*", "tblproduk", stLinkCriteria) Then 'kelampaian
    MsgBox "Nama Spesis ini, " & NewNama & ", Telah wujud dalam Database." _
    & vbCr & vbCr & "Sila semak semula Nama Spesis...!", vbInformation, "Duplicate information"
    'Me.Undo

    End If
    IDProduk = DLookup("(Idproduk)", "tblproduk", stLinkCriteria)
    Me.DataEntry = False
    DoCamd.FindRecord IDProduk, , , , , acCurrent

    End Sub

    please help me...i don't know how to fix it...

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Type mismatch would imply the nama field is numeric rather than text. See here:

    http://www.theaccessweb.com/general/gen0018.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    except the stkLinkCriteira worked in the DCount?

    Try removing the brackets around Idproduk - they imply a numerical calculation

    DLookup("Idproduk", "tblproduk", stLinkCriteria)

    or use square brackets

    DLookup("[Idproduk]", "tblproduk", stLinkCriteria)

  6. #6
    suzana is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    May 2019
    Posts
    6
    it's doesn't work at all.. it's still show run time error 13...type mismatch...hmmm...what should i do...truely i am know nothing about vba...this is my first learning on vba.. on the spot...

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    show some examples of the data and the datatypes you are using which generates the error.

    your IDProduk variable is declared as an integer - perhaps the one returned by your lookup is long?

    Also dlookup will return null if not found, which you cannot assign to an integer variable

  8. #8
    suzana is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    May 2019
    Posts
    6
    i guess the picture bellow is what you mean

    Click image for larger version. 

Name:	type data.jpg 
Views:	17 
Size:	83.5 KB 
ID:	38555

    Click image for larger version. 

Name:	type data 2.jpg 
Views:	18 
Size:	58.5 KB 
ID:	38556
    hope that you can help me find solution...

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Use this to see what stLinkCriteria contains at runtime.

    http://www.baldyweb.com/ImmediateWindow.htm

    and post the result here.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    suzana is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    May 2019
    Posts
    6
    i try and i got this

    [nama] = 'kelampaian'

    picture below:

    Click image for larger version. 

Name:	debug2.jpg 
Views:	19 
Size:	33.5 KB 
ID:	38578

  11. #11
    suzana is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    May 2019
    Posts
    6
    hope that u can help me sir...

  12. #12
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I'll bet is Nama a lookup field. show us lookup tab for nama field if you don't know what I mean.
    Quite possibly you fixed syntax problem only to uncover type mis-match?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I think the data type would be numeric if that was the case. Try removing the parentheses around the field name.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Add the little red code to complete the comparison. The type mismatch is between Boolean and numeric.
    Code:
    Private Sub Nama_AfterUpdate()
    Dim NewNama As String
    Dim stLinkCriteria As String
    Dim IDProduk As Integer
    NewNama = Me.Nama.Value
    stLinkCriteria = "[nama] = '" & NewNama & "'"
    If DCount("*", "tblproduk", stLinkCriteria) > 0 Then 'kelampaian
    MsgBox "Nama Spesis ini, " & NewNama & ", Telah wujud dalam Database." _
    & vbCr & vbCr & "Sila semak semula Nama Spesis...!", vbInformation, "Duplicate information"
    'Me.Undo
    End If
    IDProduk = DLookup("(Idproduk)", "tblproduk", stLinkCriteria)
    Me.DataEntry = False
    DoCamd.FindRecord IDProduk, , , , , acCurrent
    End Sub

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

Similar Threads

  1. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  2. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  3. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  4. Replies: 4
    Last Post: 07-25-2012, 04:01 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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