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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why am I getting this error? 1

Status
Not open for further replies.

Entrepenueress

Technical User
Aug 12, 2002
16
US
I have had many suggestions as to how to make a Browse button work in a form. The only one I could make work is the one from Microsoft's resource web site. But, I keep getting an error once I choose the file and push OK. It says that I don't have enough room in the field for the info I'm trying to put in there. I can't figure it out. If anyone would be willing to look at this database and help me figure out why I am getting this error, I would be very grateful. Make sure to press SHIFT as you open the database so it will put it into ADMIN mode. Thanks!!

Download database at:
Here's where I got the instructions:
 
well, my first thought is that this text box you are tring to put the data into, is a bound text box, and the field in the table has a limite that's to short for the ammount of text that needs to go in... try making the field size bigger on the table level. If that doesn't help i'll take a look at the db...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Good thinking, but I did try that. I set the size of the field to the maximum 255 characters. I would really appreciate you taking a look. Thank you!
 
Sure, email it to me...

junior1544@jmjpc.net junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
I just went to Q303066 and made my module like this:

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Function LaunchCD(strform As Form) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strform.Hwnd
sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
"JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = "C:\"
OpenFile.lpstrTitle = "Select a file using the Common Dialog DLL"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "A file was not selected!", vbInformation, _
"Select a file using the Common Dialog DLL"
Else
LaunchCD = Trim(OpenFile.lpstrFile)
End If
End Function

AND THEN MADE MY FORM LIKE THIS:

Private Sub cmdOpenr_Click()

Me!Text1 = LaunchCD(Me)
End Sub


AND IT WORKED LIKE A DREAM.


rollie@bwsys.net
 
The problem Entrepenueress is having is that the trim isn't working... i don't know why, but i have emailed a copy of the db she sent to me, back to her with little changes... i changed the trim to a custom function called trimnull and it is as follows...

Private Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
intPos = InStr(strItem, vbNullChar)
If intPos > 0 Then
TrimNull = Left(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function


and it worked fine for me...

just wanted to let you know my solution.

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
your structure starts w/ lpstrfile filled with Chr(0). The trim function does not remove these (although they 'look like' spaces, they are NOT!), so the trim attempts in LaunchCD and the calling fumctions have no effect, and the var being returned is actually 257 characters, not the 30 or so yoy might expect.

The following snippet replaces the If Block at hte bottom of your LaunchCd procedure and corrects the problem of the file name returned.

My impression (from looking at the form) is that you expect an image to also be placed in the pict box to the leaft of the form -but that isn't going to happen in any of the code I looked at for the stated problem, and doesn't appear to be included elsewhere, as I can run the browse function and get the file name in the box, but no image appears in the pic box.




Code:
        If lReturn = 0 Then
            MsgBox "A file was not selected!", vbInformation, _
              "Select a file using the Common Dialog DLL"
         Else
            tmp = (OpenFile.lpstrFile)
            tmpLen = InStr(tmp, Chr(0))
            tmp = Left(tmp, tmpLen - 1)
            LaunchCD = Trim(tmp)
         End If
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
You guys are all great. Thank you so much for your help. Thanks to Junior1544 for helping me out of this mess.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top