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
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