Results 1 to 11 of 11
  1. #1
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141

    Open form to record # in ComboBox

    Okay - I am close.


    I have the Combo18 defaulted to 0
    when I click the button - if the Combo18 is 0, it opens Form 00_360_Request_360 to a new record, this works fine
    I want : If Combo18 is not 0 (Combo18 is populated from the Primary Key "TicketID" (AutoNumber) on the table) or >0 I want it to open to the record number that is in Combo18
    Code so far:
    Code:
    Private Sub Command0_Click()
    Dim VarID As Integer
    VarID = Me.Combo18
    If VarID = 0 Then
        DoCmd.OpenForm "00_360_Request_360", , , , , acHidden
        DoCmd.GoToRecord acDataForm, "00_360_Request_360", acNewRec
        DoCmd.OpenForm "00_360_Request_360", , , , , acDialog
    ElseIf VarID > 0 Then
        DoCmd.OpenForm "00_360_Request_360", , , , , acHidden
        DoCmd.GoToRecord acDataForm, "00_360_Request_360", "TicketID=" & VarID
        DoCmd.OpenForm "00_360_Request_360", , , , , acDialog
    End If
    Error Msg: Type Mismatch on line:
    Code:
    DoCmd.GoToRecord acDataForm, "00_360_Request_360", "TicketID=" & VarID

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    PK's and FK's are typically of type Long Integer in Access because of the AutoNumber type
    Dim VarID As Long

  3. #3
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    made the change

    Dim VarID As Long

    Still getting type mismatch on the same line

    DoCmd.GoToRecord acDataForm, "00_360_Request_360", "TicketID=" & VarID

    I checked the Table: TicketID is the right column
    It is in the Form as a Txt Box TicketID

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I guess that kinda makes sense because the initialization of the variable would throw an exception if the combo value was larger than 32,200(or thereabout). Your code would not have gotten to the Goto method.

    Not sure what this means
    I checked the Table: TicketID is the right column
    It is in the Form as a Txt Box TicketID


    If the textbox is bound to the table, you want to verify the data type in the field in the table. If everything stated within this thread is fact, that leaves data type text at the table.

    Perhaps you are confusing an error you received earlier when your variable was type variant. If this is the case, the issue most likely lies in the combo where the combo is multicolumn and you are initializing your variable with the wrong column form the combo.

  5. #5
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    the combo box is unbound - The data row source is query based on the Table field "TicketID"
    Data Type in table is AutoNumber

    I set the ComboBox format : General Number when I started getting the error

    Column count = 1 Bound Column =1

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What is the data type of the field named, "TicketID"? While in design view of the table object, check the properties of the field to verify its data type.

  7. #7
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    Auto Number : Long Integer

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Try this... Go to your table in Datasheet View and locate a random record. Make a note of the value for field TicketID (maybe something like 500). Now test some VBA code using a literal value. See if you can get your Command Button to open form "00_360_Request_360" and display record 500 or another number of your choice.

    Use the following code in your Command Buttons click event. Notice I commented out all of your original code and added one line for testing purposes.
    Code:
    DoCmd.OpenForm "00_360_Request_360", , , "TicketID=500"
    '
    '
    '
    'Dim VarID As Integer
    'VarID = Me.Combo18
    'If VarID = 0 Then
    '    DoCmd.OpenForm "00_360_Request_360", , , , , acHidden
    '    DoCmd.GoToRecord acDataForm, "00_360_Request_360", acNewRec
    '    DoCmd.OpenForm "00_360_Request_360", , , , , acDialog
    'ElseIf VarID > 0 Then
    '    DoCmd.OpenForm "00_360_Request_360", , , , , acHidden
    '    DoCmd.GoToRecord acDataForm, "00_360_Request_360", "TicketID=" & VarID
    '    DoCmd.OpenForm "00_360_Request_360", , , , , acDialog
    After you get that to work, continue trouble shooting your code with the literal value of 500 or another number of your choice. The very last step/implementation should be implementing the combo to dynamically set the value of a variable. For now, use the literal value 500 (or...) until you get the functionality you are after.

  9. #9
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    good thought
    I tried that and it opens at the first record (not the record number we chose)

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The code I provided will open the form with a filtered recordsetset. It will display one record. The record will represent the value in the Where Criteria "TicketID=500"

    If there is not a match, you will see a blank form without any controls displayed.

  11. #11
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141
    Finally got it to work - I discarded the GotoRecord and used Find Record: works great now
    Code:
    Dim VarID As Long
    VarID = Me.Combo18
    If VarID = 0 Then
        DoCmd.OpenForm "00_360_Request_360", , , , , acHidden
        DoCmd.GoToRecord acDataForm, "00_360_Request_360", acNewRec
        DoCmd.OpenForm "00_360_Request_360", , , , , acDialog
    ElseIf VarID > 0 Then
        DoCmd.OpenForm "00_360_Request_360", , , , , acHidden
        DoCmd.FindRecord VarID, , True, , True
        DoCmd.OpenForm "00_360_Request_360", , , , , acDialog
        
    End If
    DoCmd.Close acForm, Me.Name

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

Similar Threads

  1. Replies: 5
    Last Post: 06-19-2013, 08:01 AM
  2. Use combobox to select form to open
    By gemadan96 in forum Forms
    Replies: 11
    Last Post: 11-15-2012, 01:42 PM
  3. Replies: 1
    Last Post: 05-31-2012, 01:01 PM
  4. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  5. open form based on combobox
    By bigmac in forum Forms
    Replies: 3
    Last Post: 04-09-2012, 11:25 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