2 questions re forms controls

  • Thread starter Thread starter postman
  • Start date Start date
P

postman

1. How to open the 'Get External Data > Import' wizard to import data into
access (from a text file) coded to a form control.
2. How to open a form that automatically selects a) a row. b) navigate via
arrow controls up & down then c) 'Copy & Paste' the row to another
sub-datasheet on the same form via another control on that form.

Thanks in advance.
 
postman said:
1. How to open the 'Get External Data > Import' wizard to import data into
access (from a text file) coded to a form control.

Do you want the actual wizard to start, or do you want to just have the user
choose the file, and you already have a import spec setup?

I will assume that you want the 2nd approach, as having a general button to
start the import wizard might be too complex for new users.

The command in code transferText

So, you could go:

strFileImprotName = "The File Name"

if strFileImportName = then
exit sub
end if

docmd.TransferText acImportDelim,"mySpec","destTable",strGetFileName,true

Check out the TransferText in the help.

And, if you want to pop open the file dialog box to browse to the file, then
use tghe follwig to pop up the windows dialog

http://www.mvps.org/access/api/api0001.htm

2. How to open a form that automatically selects a) a row.

You don't mention how this row is to be selected? Do you with to pass this
value to the form when you open it? It is just not clear how/when/where you
want this row to be selected? To open a form to ONE record, you can simply
go:

docmd.OpenForm "frmCustomers",,,"id = 123"

The above would open he form, and then send the form to the above one
record. However, in your case, it seems we want to open the form, but that
form might have many records, and we just want to position the record to id.
Lets assume this, and use 123 for our example. We can go

docmd.OpenForm "my",,,,,,123

Note the number of commas...we are simply passing the value of 123 to the
form, and we can example this value passed.

So, now, in the forms on load event, we position the form to customer with
id = 123

me.RecordSet.FindFirst "id = " & me.OpenArgs

b) navigate via
arrow controls up & down

The above is generally the default for a datasheet, but if you are using a
continues form, then you need to add the following code to the forms keydown
event handler, and set the forms keypreview = yes.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' key hand
On Error Resume Next

Select Case KeyCode

Case vbKeyUp
KeyCode = 0
DoCmd.GoToRecord acActiveDataObject, , acPrevious

Case vbKeyDown
KeyCode = 0
DoCmd.GoToRecord acActiveDataObject, , acNext

End Select

End Sub
c) 'Copy & Paste' the row to another sub-datasheet on the same form via
another control on that form.

Copy and paste sounds like a bad word here, we you want to do is copy the
reocrd via a append query to the other table?

You can go:

dim strSql as string

strSql = "INSERT INTO tblSecondTable ( Description, Catagory, amount ) " & _
" SELECT Description, Catagory, amount FROM tblAnswers " & _
" where ID = " & me!id

CurrentDB.Execute

You also should do a requery on the 2nd form to show the above update...

me.MySubForm2.requery
 
thanks,
it'll take me a while to digest all that code & where to put it...I may have
to check back with you on some of it.
Do you want the actual wizard to start, or do you want to just have the
user choose the file, and you already have a import spec setup?
Yes the second option would be fine.
No I don't have an import spec setup, I would like it to be though. The
files are text files, tab delimited, maybe you could just explain that setup
bit so I could implement it. Otherwise just popping up the wizard from a
form control will be fine.
You don't mention how this row is to be selected? Do you with to pass this
value to the form when you open it? It is just not clear how/when/where
you want this row to be selected? To open a form to ONE record, you can
simply go:

The record row to be selected from the sub-datasheet records will be pulled
in via combo box, & will return about 10 records to the datasheet. I need
the datasheet row to be auto selected, then the user can navigate using the
up down controls to select the right record, or even better highlight the
combo box criteria record in the subdatasheet itself (although search
criteria maybe incomplete i.e.. part word)
With the copy/paste I have manually been selecting the record with my
mouse then use right click context menu to copy/paste over to the other
datasheet. So it would be nice if I could just tab over to it & paste
without having to use the context menu but rather a control button on the
form. Although you are right about the append query doing all that...I'll
give it some thought.
You also should do a requery on the 2nd form to show the above update...

me.MySubForm2.requery

Sorry where should the above code go, is it in the afterupdate box?

Thanks alot.
-----------------------------------------------------------------------------------------------------
 
thanks,
it'll take me a while to digest all that code & where to put it...I may have
to check back with you on some of it.
Do you want the actual wizard to start, or do you want to just have the
user choose the file, and you already have a import spec setup?
Yes the second option would be fine.
No I don't have an import spec setup, I would like it to be though. The
files are text files, tab delimited, maybe you could just explain that setup
bit so I could implement it. Otherwise just popping up the wizard from a
form control will be fine.
You don't mention how this row is to be selected? Do you with to pass this
value to the form when you open it? It is just not clear how/when/where
you want this row to be selected? To open a form to ONE record, you can
simply go:

The record row to be selected from the sub-datasheet records will be pulled
in via combo box, & will return about 10 records to the datasheet. I need
the datasheet row to be auto selected, then the user can navigate using the
up down controls to select the right record, or even better highlight the
combo box criteria record in the subdatasheet itself (although search
criteria maybe incomplete i.e.. part word)
With the copy/paste I have manually been selecting the record with my
mouse then use right click context menu to copy/paste over to the other
datasheet. So it would be nice if I could just tab over to it & paste
without having to use the context menu but rather a control button on the
form. Although you are right about the append query doing all that...I'll
give it some thought.
You also should do a requery on the 2nd form to show the above update...

me.MySubForm2.requery

Sorry where should the above code go, is it in the afterupdate box?

Thanks alot.
 
You also should do a requery on the 2nd form to show the above update...
Sorry where should the above code go, is it in the afterupdate box?

The requery would be put RIGHT AFTER the line of code that copies the data
via that append query. Since this code is running "behind" the forms, then
he form does not know to refresh..and show the new records (in this cases
ONE record) that is now in the table, so you will have to do a requery on
the form (or listbox, or sub-form, or whatever you used to display the
results on the right side of the screen).
 
Back
Top