Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16

    Opening Specific Records using a button

    Hi All,



    I have a form [frmMain] on which lots of information is entered, including [Date] and [Code]. There will only be one record with each combination of the two.

    I have a menu on another form [frmMenu], where I have a [Date] and [Code] field, and a button.

    How do I get the button to open the [frmMain] form on the record matching the values in the [Date] and [Code] fields on the menu?

    Thanks in advance!

  2. #2
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16
    EDIT just to say I know I'm close

    I'm at

    stLinkCriteria = "[GIOCode]=" & Me![GIOSearch] And "[MonthEnding]=" & "#" & Me![MonthSearch] & "#"

    it just says type mismatch?

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    date is a reserved word in access, you want to rename that field.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    stLinkCriteria = "[GIOCode]=" & Me![GIOSearch] & " And [MonthEnding]=" & "#" & Me![MonthSearch] & "#"
    AND should be included within quotes, and be sure to include the space before.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    And if the code is text you need to wrap it in single codes:
    Code:
    stLinkCriteria = "[GIOCode]='" & Me![GIOSearch] & "' And [MonthEnding]=#" & Me![MonthSearch] & "#"
    Cheers,
    Vlad

  6. #6
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16
    Quote Originally Posted by davegri View Post
    AND should be included within quotes, and be sure to include the space before.
    homegrownandy, it's not actually date.

    Dave, this doesn't return a mismatch but it also just returns a blank field? What would that mean?

  7. #7
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16
    Quote Originally Posted by Gicu View Post
    And if the code is text you need to wrap it in single codes:
    Code:
    stLinkCriteria = "[GIOCode]='" & Me![GIOSearch] & "' And [MonthEnding]=#" & Me![MonthSearch] & "#"
    Cheers,
    Vlad
    Thanks Vlad

    'Data type mismatch in criteria expression'

    Does it matter that the GIOCode is number format?

  8. #8
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16
    Just to sum up. I have code:

    Private Sub Command5_Click()
    On Error GoTo Err_Command5_Click


    Dim stDocName As String
    Dim stLinkCriteria As String


    stDocName = "frmMain"

    stLinkCriteria = "[GIOCode]=" & Me![GIOSearch] & " And [MonthEnding]=#" & Me![MonthSearch] & "#"
    DoCmd.OpenForm stDocName, , , stLinkCriteria


    Exit_Command5_Click:
    Exit Sub


    Err_Command5_Click:
    MsgBox Err.Description
    Resume Exit_Command5_Click

    End Sub

    The two fields on the menu are [GIOSearch] and [MonthSearch] and the two fields to pick up from frmMain are [GIOCode] and [MonthEnding]

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    if number you do not need the single quotes.

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Can you show us a sample value for MonthEnding?

  11. #11
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16
    I see in tblMain a record with GIOCode 6002538 and MonthEnding 01/12/2018 and input those into the fields in the menu which are the same format. Yet the button returns the form frmMain with no data

    stLinkCriteria = "[GIOCode]=" & Me![GIOSearch] & " And [MonthEnding]=#" & Me![MonthSearch] & "#"

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Is the GioCode type set as Long or is it text - when you look at the value in the datasheet feeding the frmMain form is it left or right justified?

    Put a break on the Docmd.OpenForm line and look at the value of your stLinkCriteria string in the immediate window just to confirm that everything is there.

    Cheers,
    Vlad

  13. #13
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16
    Quote Originally Posted by Gicu View Post
    Is the GioCode type set as Long or is it text - when you look at the value in the datasheet feeding the frmMain form is it left or right justified?

    Put a break on the Docmd.OpenForm line and look at the value of your stLinkCriteria string in the immediate window just to confirm that everything is there.

    Cheers,
    Vlad
    It's right justified.

    Not sure what the second part of your post means?

  14. #14
    Dan9684 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2019
    Posts
    16
    Hi just a thought on this

    My code says stLinkCriteria = "[GIOCode]=" & Me![GIOSearch] & " And [MonthEnding]=#" & Me![MonthSearch] & "#"

    MonthSearch and MonthEnding are both 01/12/2018 as in 1st December.

    When I run a query from the database for that date and look at the SQL view it says:
    WHERE (((tblMain.MonthEnding)=#12/1/2018#));

    Could it be this format of the date I'm getting wrong? How can I change the format if so?

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Try:

    stLinkCriteria = "[GIOCode]=" & Me![GIOSearch] & " And [MonthEnding]=#" &format(Me![MonthSearch],,"MM/DD/YYYY") & "#"

    Cheers,
    Vlad

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 07-20-2014, 03:59 PM
  2. Replies: 5
    Last Post: 02-13-2014, 05:27 AM
  3. Replies: 15
    Last Post: 04-17-2012, 01:42 PM
  4. Replies: 11
    Last Post: 03-20-2012, 08:55 AM
  5. Replies: 2
    Last Post: 06-09-2011, 09:47 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