Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New record by clicking in a list

Status
Not open for further replies.
Jan 29, 2002
30
GB
Hi there,

I have a form which just shows a list box with company name, key id and postcode in it.

I want to select a record and click a command button to take me to another form, the form is to add new data based on the information from the list box in the other form.

does this make sense.

Oh and can anyone help!

Cheers
James
 
How are ya jspe377522 . . . . .

In the [blue]On Click[/blue] event of the button, copy/paste the following code (you substitute names in [purple]purple[/purple]):
Code:
[blue]   DoCmd.OpenForm, "[purple][b]FormName[/b][/purple]", acnormal[/blue]
Then in the [blue]On Load[/blue] event of the opened form, try the something like the followingL
Code:
[blue]   Dim frm As Form
   Set frm = Forms![purple][b]CallingFormName[/b][/purple]

   docmd.RunCommand acCmdRcordsGoToNew
   Me![purple][b]Name1[/b][/purple] = [purple][b]frm!Name1/b][/purple]
   Me![purple][b]Name2[/b][/purple] = frm![purple][b]Name2[/b][/purple]
   Me![purple][b]Name3[/b][/purple] = frm![purple][b]Name3[/b][/purple]

   set frm = nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Sorry . . . hit submit my mistake . . . .

Then in the [blue]On Load[/blue] event of the opened form, try the something like the following:
Code:
[blue]   Dim frm As Form
   
   Set frm = Forms![purple][b]CallingFormName[/b][/purple]

   docmd.RunCommand acCmdRcordsGoToNew
   
   Me![purple][b]Name1[/b][/purple] = frm![purple][b]Name1[/b][/purple]
   Me![purple][b]Name2[/b][/purple] = frm![purple][b]Name2[/b][/purple]
   Me![purple][b]Name3[/b][/purple] = frm![purple][b]Name3[/b][/purple]

   set frm = nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Sorry about this

Did as said and got the following error

Complie error:

Argument not optional

Wehen pressing comand button, shows first bit of code

Cheers
James
 
just a thought aceman...

since he's got all this info in a listbox, shouldn't he be setting:
me!name1 = frm!listBoxName!column1
...

jspe, can you post the line of code that causes the error? It sounds like you're calling a function and not providing enough arguments, so it'd be helpful for us to see the function...

Procrastinate Now!
 
Private Sub Command9_Click()

DoCmd.OpenForm , "frm_Contacts", acNormal

End Sub

Cheers
James
 
firstly, give your button a proper name!

secondly, is that the exact syntax you're using? If it is, then you've not given the form name argument... get rid of the ,

docmd.OpenForm , FormName, ...

Procrastinate Now!
 
im being really thick,

which , do i remove i have removed both with no luck!!

Cheers
James
 
lol, the first one...

the syntax should be:

docmd.WhateverCommand "firstArgument", "2ndArgument", "3rd...

Procrastinate Now!
 
jspe377522 . . . . .

[blue]Crowley16[/blue] is right. Somehow I lost sight of the ListBox. . . So, after [blue]fresh coffee[/blue] lets see what we can really do.

You don't need the button. Just add the [blue]DoCmd[/blue] hat follows to the AfterUpdate event of the ListBox:
Code:
[blue]DoCmd.OpenForm "frm_Contacts", acNormal[/blue]
Then in the [blue]On Load[/blue] event of the [blue]Opened Form[/blue] copy/paste the following:
Code:
[blue]   Dim LB As ListBox
   
   Set LB = Forms![purple][b]CallingFormName[/b][/purple]![purple][b]ListBoxName[/b][/purple]
   
   Me![purple][b]ControlName1[/b][/purple] = LB.Column([purple][b]?[/b][/purple])
   Me![purple][b]ControlName2[/b][/purple] = LB.Column([purple][b]?/b][/purple])
   
   Set LB = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top