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

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,690
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
Joined
Nov 14, 2005
Messages
1,690
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
Joined
Sep 25, 2012
Messages
163
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
Joined
Nov 14, 2005
Messages
1,690
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
Joined
Sep 25, 2012
Messages
163
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".
 

Forum statistics

Threads
1,086,094
Messages
5,387,798
Members
402,076
Latest member
MotoMoto

Some videos you may like

This Week's Hot Topics

Top