Results 1 to 6 of 6

Thread: Help!!

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Help!!

    I am relatively new to VB and brand new to vbforum. I am trying to make an input box from a form in a project and having a hard time getting it to collect data from my Data1. What do I need to tell someone so I can get some ideas?

  2. #2
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Manila, Philippines
    Posts
    486

    Re: Help!!

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim x
    3. x = InputBox("Please enter here!", "Your Input")
    4. MsgBox x
    5. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Help!!

    Thanks Kulitag, but I mean I made another form and named it frmInput. When I call it I want it to collect data from a database just like an inputbox, but I can't get it to work. It won't return a value. I don't know the code for the inputbox function.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Help!!

    Post the code in the form.

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Help!!

    You have to declare you variables as Public in order to 'see' them from other forms.

    For example, declare on Form1

    Public strName As String

    then from Form2 you can access it with

    MsgBox Form1.strName

    ...

    It's the same when you refference controls: (on Form2)

    MsgBox Form1.txtData.Text

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Help!!

    **This is code from the first form calling an inputbox for info.**


    Option Explicit

    Public Function InputForm(strInput As String) As String
    strInput = InputForm
    'frmFloorPlan.txtApt = strApt
    End Function

    Private Sub cmdFind_Click()
    Dim strApt As String

    strApt = InputBox("Enter the Movie Title you want to find. Type it just as it appears on the box.", "Find a Title")
    strApt = "Apartment = " & "'" & strApt & "'"
    Data1.Recordset.FindFirst strApt
    txtApt.SetFocus
    'frmInput.Show
    'frmInput.txtApt.SetFocus
    End Sub



    Private Sub cmdPrint_Click()
    ' replace all "Picture1" below with name of the Picture Box or
    ' other control that you want to print its picture.
    ' replace the "0, 0" below with the coordinates of the picture
    ' on the printed paper. "0, 0" will print the picture in the
    ' upper left corner. If you want to print the picture where
    ' the printer's head is currently found, instead of "0, 0"
    ' use "Printer.CurrentX, Printer.CurrentY" (if you printed text
    ' and then you'll print the picture with the
    ' "Printer.CurrentX, Printer.CurrentY" coordinates, the picture
    ' will be printed immediately after the text).
    ' If you want to enlarge or to reduce the size of the picture,
    ' replace the "Picture1.Width, Picture1.Height" with your
    ' desirable picture width and height.
    ' for example: "Picture1.Width * 2, Picture1.Height * 2"
    ' will print the picture in double size, and:
    ' "Picture1.Width * 0.5, Picture1.Height * 0.5"
    ' will print the picture in half size.
    Printer.Orientation = vbPRORLandscape
    Printer.PaintPicture imgFloorPlan.Picture, 0, 0, _
    imgFloorPlan.Width * 2, imgFloorPlan.Height * 2
    ' use the EndDoc command if the picture is the last item you want
    ' to print on the paper
    Printer.EndDoc
    End Sub

    Private Sub cmdQuit_Click()
    End
    End Sub

    Private Sub Form_Load()
    lblDate.Caption = Date
    imgFloorPlan = LoadPicture("C:\Floor Plans\Canyon Office.JPG")
    End Sub

    'To make a watch from Visual Basic, put one timer on the Form and a Label control. Set the Interval property of the Timer into 1000 and start coding this in the Timer1_Timer event.

    Private Sub Timer1_Timer()
    lblTime.Caption = Format(Now, "h:mm AMPM")
    End Sub


    Private Sub txtApt_GotFocus()
    txtFloorPlan.Text = StrConv(txtFloorPlan.Text, vbProperCase)
    If txtFloorPlan.Text = "R" Then imgFloorPlan = LoadPicture("C:\Floor Plans\R.bmp")
    If txtFloorPlan.Text = "P" Then imgFloorPlan = LoadPicture("C:\Floor Plans\P.bmp")
    If txtFloorPlan.Text = "Q" Then imgFloorPlan = LoadPicture("C:\Floor Plans\Q.bmp")
    If txtFloorPlan.Text = "S" Then imgFloorPlan = LoadPicture("C:\Floor Plans\S.bmp")
    If txtFloorPlan.Text = "Ss" Then imgFloorPlan = LoadPicture("C:\Floor Plans\S.bmp")
    If txtFloorPlan.Text = "Sp" Then imgFloorPlan = LoadPicture("C:\Floor Plans\S.bmp")
    If txtFloorPlan.Text = "Rp" Then imgFloorPlan = LoadPicture("C:\Floor Plans\R.bmp")
    If txtFloorPlan.Text = "Rs" Then imgFloorPlan = LoadPicture("C:\Floor Plans\R.bmp")
    End Sub


    **This is code for the second form that I want to perform like an inputbox and return a value to the first form. The first part is just code to get rid of the title bar of the form.**

    Private Declare Function SetWindowLong Lib "user32" _
    Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" _
    Alias "GetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Const GWL_STYLE = (-16)
    Private Const WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const WS_SYSMENU = &H80000

    Private Declare Function SetWindowPos Lib "user32" _
    (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
    ByVal x As Long, ByVal y As Long, _
    ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Enum ESetWindowPosStyles
    SWP_SHOWWINDOW = &H40
    SWP_HIDEWINDOW = &H80
    SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
    SWP_NOACTIVATE = &H10
    SWP_NOCOPYBITS = &H100
    SWP_NOMOVE = &H2
    SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering
    SWP_NOREDRAW = &H8
    SWP_NOREPOSITION = SWP_NOOWNERZORDER
    SWP_NOSIZE = &H1
    SWP_NOZORDER = &H4
    SWP_DRAWFRAME = SWP_FRAMECHANGED
    HWND_NOTOPMOST = -2
    End Enum

    Private Declare Function GetWindowRect Lib "user32" ( _
    ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type

    Private Function ShowTitleBar(ByVal bState As Boolean)
    Dim lStyle As Long
    Dim tR As RECT

    ' Get the window's position:
    GetWindowRect Me.hwnd, tR

    ' Modify whether title bar will be visible:
    lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
    If (bState) Then
    Me.Caption = Me.Tag
    If Me.ControlBox Then
    lStyle = lStyle Or WS_SYSMENU
    End If
    If Me.MaxButton Then
    lStyle = lStyle Or WS_MAXIMIZEBOX
    End If
    If Me.MinButton Then
    lStyle = lStyle Or WS_MINIMIZEBOX
    End If
    If Me.Caption <> "" Then
    lStyle = lStyle Or WS_CAPTION
    End If
    Else
    Me.Tag = Me.Caption
    Me.Caption = ""
    lStyle = lStyle And Not WS_SYSMENU
    lStyle = lStyle And Not WS_MAXIMIZEBOX
    lStyle = lStyle And Not WS_MINIMIZEBOX
    lStyle = lStyle And Not WS_CAPTION
    End If
    SetWindowLong Me.hwnd, GWL_STYLE, lStyle

    ' Ensure the style takes and make the window the
    ' same size, regardless that the title bar etc
    ' is now a different size:
    SetWindowPos Me.hwnd, _
    0, tR.Left, tR.Top, _
    tR.Right - tR.Left, tR.Bottom - tR.Top, _
    SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED

    Me.Refresh

    ' Ensure that your resize code is fired, as the client area
    ' has changed:
    'Form_Resize

    End Function

    'To try out the hiding and showing the title bar, add a CheckBox to the project's form. Set the check box's Value property to 1 (Checked). Then put the following code under the Check box's click event:

    Private Sub Check1_Click()
    If (Check1.Value = Checked) Then
    ShowTitleBar True
    Else
    ShowTitleBar False
    End If
    End Sub


    Private Sub cmdCancel_Click()
    Response = vbCancel
    Unload Me
    End Sub

    Private Sub cmdOK_Click()
    Dim strApt As String

    'Response = vbOK

    strInput = InputForm
    txtApt.Text = strApt '"Apartment = " & "'" & strApt & "'"
    'Data1.Recordset.FindFirst strApt
    'strInput = strApt
    frmFloorPlan.txtApt = strApt


    Unload Me
    End Sub

    Private Sub Form_Load()
    Check1.Value = Unchecked

    End Sub
    Last edited by Carl Newman; May 27th, 2005 at 07:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width