Select data (Row) in one table and have it load/add to abother table

gheyman

Well-known Member
I have data in an ODBC table. What I need to do is when someone selects a record in that table, have it automatically load data from that record to another table.

Not sure where to even start or what to research. Any advice/direction is appreciated
 

gheyman

Well-known Member
Here is where I am currently heading;

I put a Combo box on my form. It is tied to the ODBC Table. I created an append query where I am using that Combo as a Criteria in the query. So the selection the user makes "Filters" the query down to the one selected record. So know once the query is "filtered" to the criteria, I can run the Append query function and it adds the one new record.

BUT THE PROBLEM I HAVE NOW IS:

If the user doesn't make a selection in the Combo Box, then it appends ALL the records from the first table. I never want that to happen.

So How do I rewrite this code so it doesn't run if there isn't a selection in the Combo Box???

Code:
Private Sub Command29_Click()
On Error GoTo Command29_Click_Err

  DoCmd.SetWarnings False

    DoCmd.OpenQuery "qry_vluVendor_MakeTable", acViewNormal, acEdit
    DoCmd.Close acQuery, "qry_vluVendor_MakeTable"


Command29_Click_Exit:
    Exit Sub

Command29_Click_Err:
    MsgBox Error$
    Resume Command29_Click_Exit
    
    

End Sub
[\code]
 
Last edited:

petertenthije

Board Regular
You can add a IF statement referring to the field on the form. If the field is blank, don’t do anything, otherwise run the macro.
 

gheyman

Well-known Member
Code:
Private Sub Command29_Click()
On Error GoTo Command29_Click_Err

  DoCmd.SetWarnings False

If IsNull(ComboVendorASL) Then
Else
    DoCmd.OpenQuery "qry_vluVendor_MakeTable", acViewNormal, acEdit
    DoCmd.Close acQuery, "qry_vluVendor_MakeTable"
    
    DoCmd.RepaintObject acForm, "frm_Add_Supplier"
        DoCmd.RunCommand acCmdRefresh
    DoCmd.GoToRecord , "", acLast
End If

Command29_Click_Exit:
    Exit Sub

Command29_Click_Err:
    MsgBox Error$
    Resume Command29_Click_Exit
    
    DoCmd.RepaintObject acForm, "frm_Add_Supplier"
        DoCmd.RunCommand acCmdRefresh
    DoCmd.GoToRecord , "", acLast
    DoCmd.OpenForm "frm_Add-Supplier", acNormal, "", "", , acNormal


End Sub
Thanks. This solves the blank combo issue, but I cannot get the form to refresh so it show the table data with the new record (my forms source is the table I am appending to.
 

petertenthije

Board Regular
Thanks. This solves the blank combo issue, but I cannot get the form to refresh so it show the table data with the new record (my forms source is the table I am appending to.
Could you try adding "Me.Requery" or "form.requery" to the macro.

The former recalculates everything, the latter only the form. Depending on how many queries feed your form you may need to use "Me.Requery".
 

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top