Cant set focus....

CEH

Curtis
Local time
Today, 13:42
Joined
Oct 22, 2004
Messages
1,187
Have an odd little problem that I cant seem to solve.... Pick up a very simple code and form on here for linked images in a db.... I added a "Description" field and planning to add some other items..... Problem I am having is after I add the new image I want to set focus on the "Description" field.... No matter where I seem to put the line it does not set the focus!! Can somebody clue me in? This is too simple! I have to be over looking something! Code is as follows..... All works but the setfocus...


Code:
Private Sub cmdAddImage_Click()
 DoCmd.GoToRecord , , acNewRec
Call Main
End Sub

Private Sub Form_Current()
Me![imagepath].SetFocus
Me![imageframe].Picture = Me![imagepath].Text

End Sub





Sub Main()

    'Declare a variable as a FileDialog object.
    Dim fd As FileDialog

    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is a String that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.
                'MsgBox "The path is: " & vrtSelectedItem
              Me.imagepath = vrtSelectedItem
                Me![imagepath].SetFocus
                Me![imageframe].Picture = Me![imagepath].Text
              
            Next vrtSelectedItem
            
        'The user pressed Cancel.
        Else
        End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing
Me![ImageDescription].SetFocus

End Sub
 
I think it could be that your Tab Order needs adjusting to make the Description field the next one in the sequence after cmdAdd. Also on the cmdAdd LostFocus or Exit event, I would put Description.SetFocus

Where you have this line in the Sub Main is evidently the wrong place.

If you really want to track what is happening, highlight the End With line in your code (put a full stop in the far left margin) and the run the code. When it stops at this line, repeatedly Press F8 to advance through the remainder of the code, one line at a time,and see what is happening.
 
Nope, lost focus throws an error... stops the code on the AddNewRec line........
And.... After a new image is added the tab key does nothing. ???
 
Last edited:
I think I know now the problem, but not how to fix it...... When the focus is taken from the Access form to the dialog box, it never returns to the form..... therefor it won't set focus to my field. Being that the dialog box is not an Access dialog box, how do I set the focus back to Access and the form field?
 
it could be that you've gone to a new record and haven't saved it, so it's not current.

edit: hang on...rereading...
 
have you tried putting it after Call Main?
 
Doesn't work there either..... From my searching it looks as if it would be some "Syscmd" code...... Just can't seem to find anything that works.....puts the focus back on Access.........:confused:
 
OK, after searching for hours and trying everything I can find I think I'll post this...... Can't remember who posted this originally... But I only added a couple of things.... All I am trying to do is get the cursor into the "Image Description" field after adding a new record..............
 

Attachments

hey curtis.
i could see that the form was not active after going through the routine so i added:
Code:
    [B][COLOR=green][COLOR=seagreen]Me.SetFocus[/COLOR]
[/COLOR][/B]    Me!ImageDescription.SetFocus
    Me!ImageDescription.Text = "-"
and it works. i think you could put that somewhere else if you wanted to.
 
Well Wazz.... Still not working in mine.... It puts the "dash" in..... but I did that just to see if the textbox would take input... but you still have to click anyplace on the form before the cursor appears in the Image description box.....And THAT is what I am trying to make happen.
 
guess i must have accidentally activated the form. now it's not working. sry. having the same problem here.
 
what is the description

is it a label? - you cant give a label the focus

or is it enabled=false - you cant set the focus to a field that isnt enabled

----------
only other possibility is that your with/end with block is erroring out to whatever error handler is active
 
It's a textbox... and it is enabled...
 
that is one crazy problem.
i finally found some code that is working for me now:
http://scriptorium.serve-it.nl/view.php?sid=44
it sends mouse clicks, so it's a workaround but it is working.
also, the code sends left and right clicks but it's easily changed to just left-clk.
hth!!
 
Seems like ALOT of code for something that should be easy to fix!!! I'm going to keep searching.... maybe I can locate something.
 
OK, after searching for hours and trying everything I can find I think I'll post this...... Can't remember who posted this originally... But I only added a couple of things.... All I am trying to do is get the cursor into the "Image Description" field after adding a new record..............

Want me to add something strange? I just downloaded your database and it works like you want for me (I'm on 2003 SP1). I select the image and it opens the dialog, I select one, and it goes to the description text box and has the - in it and my cursor is ready to type and I can type. How strange is that?
 
that is bizarre. there must be an obscure Option we have set up differently.
 
That is strange..... I was just looking what is on mine...actually I'll need to check 2, it acts up on my Computer at work also..... Both are using 2003, I also have 2007 on this one... Looking at the other part...... .Net Framework 3.5 SP1 and .Net Framework 2.0 Service Pack 2, and .Net Framework 3.0 Service Pack 2..........
I'm still lost......
 
And I just tested with Access 2007 at home and it works great there too. :( This is quite a mystery.
 

Users who are viewing this thread

Back
Top Bottom