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

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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:
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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".
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top